fork download
  1. import random
  2. import math
  3.  
  4. # Parameters
  5. d = 6
  6. cha = 5
  7.  
  8. def roll(Y,n=1):
  9. if n==0:
  10. return []
  11. elif n==1:
  12. return [random.randint(1,Y)]
  13. else:
  14. return roll(Y)+roll(Y,n-1)
  15.  
  16. def reroll(Y,n,c):
  17. r = sorted(roll(Y,n))
  18. c = min(c,len([x for x in r if x<=3])) # Number of rerolls
  19. R = roll(Y,c)+r[c:]
  20.  
  21. return r,R
  22.  
  23. rep = 1000
  24. data =[]
  25. for n in range(40,41):
  26. r,R=[],[]
  27. for i in range(rep):
  28. a,b = reroll(d,n,cha)
  29. r+=a
  30. R+=b
  31. avgr = sum(r)/float(rep)
  32. avgR = sum(R)/float(rep)
  33. inc = (avgR/avgr-1)*100
  34.  
  35. print('{}\t{:.2f}\t{:.2f}\t{:.2f}'.format(n,avgr,avgR,inc))
  36. # your code goes here
Success #stdin #stdout 0.14s 10108KB
stdin
Standard input is empty
stdout
40	140.00	152.01	8.58