Birthday_Problem

Run Settings
LanguageJulia
Language Version
Run Command
function birthday_issue(n) if n < factor return 1 else return BigInt(n * birthday_issue(n - 1)) end end days = 365 @printf "一年有%d天的狀況下,\n" days for persons = 1:23 global factor = days - persons + 1 @printf "有個%2d人團體,至少有2人同一天生日的機率是:" persons Pn = 1 - birthday_issue(days) / BigInt(days) ^ persons @printf "%.3f\n" Pn end
Editor Settings
Theme
Key bindings
Full width
Lines