Quick actions

cmd+k|ctrl+k

Navigation

Languages

Birthday_Problem

Snippet info

Language

Julia

Visibility

public

Author

jenkuo.chang

Created

2019-12-03T11:19:30Z

Updated

2019-12-03T11:27:30Z

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
INFO