fork download
  1. from random import randint
  2.  
  3. completed = [
  4. 0,4,3,3,3,3,1,1,1
  5. ]
  6.  
  7. def check(instances):
  8. for i, c in enumerate(completed):
  9. if instances[i] < c:
  10. return False
  11.  
  12. return True
  13.  
  14. attempts = 100
  15. total_rolls = 0
  16. highest = 0
  17. lowest = 100
  18.  
  19. for _ in range(attempts):
  20. rolls = 0
  21. instances = [0,0,0,0,0,0,0,0,0]
  22. while not check(instances):
  23. i = randint(1, 8)
  24.  
  25. while i > 0 and instances[i] >= completed[i]:
  26. i -= 1
  27.  
  28. instances[i] += 1
  29. rolls += 1
  30.  
  31. total_rolls += rolls
  32.  
  33. if rolls > highest:
  34. highest = rolls
  35.  
  36. if rolls < lowest:
  37. lowest = rolls
  38.  
  39. print(f"attempts: {attempts}, total_rolls = {total_rolls}, average_rolls = {total_rolls / attempts}, highest = {highest}, lowest = {lowest}")
Success #stdin #stdout 0.03s 11624KB
stdin
Standard input is empty
stdout
attempts: 100, total_rolls = 2051, average_rolls = 20.51, highest = 51, lowest = 19