Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function nflips(N::Integer)
- n = 0
- heads = 0
- while heads < N
- if rand(Bool)
- heads += 1
- end
- n += 1
- end
- n
- end
- function p1winpct(nheads::Integer, nsims::Integer)
- n = 0
- for i in 1:nsims
- if nflips(nheads) <= nflips(nheads)
- n += 1
- end
- end
- n/nsims
- end
- @time p1winpct(10,100000000)
- # Output:
- # 32.703553 seconds (5 allocations: 176 bytes)
- #0.53295481
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement