fork(11) download
  1. import random
  2.  
  3. win_req = 17
  4. cons_req = 6
  5. probability = 0.5
  6. runs = 200000
  7.  
  8. def get_has_3cons(seq, win_req, cons_req):
  9. cons_won = [0, 0]
  10. score = [0, 0]
  11. i = 0
  12. while score[0] < win_req and score[1] < win_req:
  13. score[seq[i]] += 1
  14. cons_won[seq[i]] += 1
  15. cons_won[1-seq[i]] = 0
  16. if cons_won[0] >= cons_req or cons_won[1] >= cons_req:
  17. return 1
  18. i += 1
  19. return 0
  20.  
  21. def gen(req):
  22. seq = []
  23. for i in range(0, 2*req-1):
  24. winner = 1
  25. if random.random() < probability:
  26. winner = 0
  27. seq.append(winner)
  28. return seq
  29.  
  30. total_has = 0
  31. total = 0
  32.  
  33. seq = gen(win_req)
  34. while total < runs:
  35. total += 1
  36. if get_has_3cons(seq, win_req, cons_req):
  37. total_has += 1
  38. seq = gen(win_req)
  39. print(total_has, total, 100.0*total_has/total, 100.0*(total-total_has)/total)
Success #stdin #stdout 3.72s 11892KB
stdin
Standard input is empty
stdout
69069 200000 34.5345 65.4655