fork(1) download
  1. import random
  2.  
  3. n = 15
  4. trials = 10000
  5.  
  6. maf_wins = 0
  7.  
  8. for t in range(trials):
  9. town = set()
  10. for i in range(n):
  11. town.add(i)
  12. day = 1
  13. while True:
  14. day = 1-day
  15. if day:
  16. if len(town) >= 3:
  17. y = random.sample(town, 1)[0]
  18. town.remove(y)
  19. continue
  20. kills = []
  21. for x in town:
  22. y = x
  23. while y == x:
  24. y = random.sample(town, 1)[0]
  25. kills.append(y)
  26. for y in kills:
  27. if y in town:
  28. town.remove(y)
  29.  
  30. if len(town) <= 1 or 0 not in town:
  31. break
  32.  
  33. if 0 in town:
  34. maf_wins += 1
  35.  
  36. print "Maf wins %d out of %d games. %f%%" % (maf_wins, trials, 100*float(maf_wins)/trials)
Success #stdin #stdout 1.02s 11552KB
stdin
Standard input is empty
stdout
Maf wins 342 out of 10000 games. 3.420000%