Advertisement
Guest User

Dice frequency calculations

a guest
Jan 9th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. tabletop = [19, 16, 2, 19, 15, 4, 9, 5, 2, 13, 7, 5, 18, 5, 1, 5, 3, 5, 20, 3]
  2. dicetower = [7, 6, 2, 15, 16, 1, 8, 17, 1, 6, 4, 8, 6, 4, 8, 11, 3, 15, 6, 6, 2, 2, 8, 12, 12, 17, 2, 1, 1, 16, 1, 3, 15, 12, 1, 11, 11, 4, 1, 4, 8, 1, 5, 13, 15, 7, 17, 14, 9, 4, 5, 20, 13, 20, 1, 2, 5, 4, 3, 8, 2, 10, 6, 2, 4, 5, 14, 11, 13, 15, 19, 2, 8, 2, 1, 1, 4]
  3.  
  4.  
  5. def freq(rolls):
  6.     results = {}
  7.     for i in range(1, 21):
  8.         results[i] = 0
  9.     for roll in rolls:
  10.         results[roll] += 1
  11.     return results
  12.  
  13. def analyse(rolls):
  14.     freqs = freq(rolls)
  15.     for roll in freqs:
  16.         count = freqs[roll]
  17.         print str(roll) + ": " + ("." * count) + " (" + str(count) + ")"
  18.  
  19.     print "Results by quartile:"
  20.     print "1-5:   " + str(sum([freqs[c] for c in range(1, 6)]))
  21.     print "6-10:  " + str(sum([freqs[c] for c in range(6, 11)]))
  22.     print "11-15: " + str(sum([freqs[c] for c in range(11, 16)]))
  23.     print "16-20: " + str(sum([freqs[c] for c in range(16, 21)]))
  24.  
  25. # Run this and call either analyse(dicetower) or analyse(tabletop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement