Guest User

Riddler Express 1/20/2017

a guest
Jan 21st, 2017
354
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function nflips(N::Integer)
  2.   n = 0
  3.   heads = 0
  4.   while heads < N
  5.     if rand(Bool)
  6.       heads += 1
  7.     end
  8.     n += 1
  9.   end
  10.   n
  11. end
  12.  
  13. function p1winpct(nheads::Integer, nsims::Integer)
  14.   n = 0
  15.   for i in 1:nsims
  16.     if nflips(nheads) <= nflips(nheads)
  17.       n += 1
  18.     end
  19.   end
  20.   n/nsims
  21. end
  22.  
  23. @time p1winpct(10,100000000)
  24.  
  25. # Output:
  26. # 32.703553 seconds (5 allocations: 176 bytes)
  27. #0.53295481
RAW Paste Data