Recently, somebody asked on Google+:
If I roll one of the five standard gaming dice (d4, d6, d8, d10, d12) and you also roll one of those, what are my chances of rolling higher, equal or lower than you, for each possible combination of dice.
I decided to write a little program to simply count it since I was unable to figure it out by thinking it through.
+-----------+--------------------------------+ | x winning | `(x(x-1))/2/(xy) = (x-1)/(2y)` | +-----------+--------------------------------+ | tie | `x/(xy) = 1/y` | | y winning | `((x(x-1))/2 + x(y-x))/(xy) = | | | 1 - ((x+1)/(2y))` | +-----------+--------------------------------+
(dolist (die-1 '(4 6 8 10 12)) (dolist (die-2 '(4 6 8 10 12)) (unless (< die-2 die-1) (let ((a 0) (b 0) (n 0)) (insert (format "d%d vs. d%d" die-1 die-2)) (newline) (newline) (insert " ") (dotimes (roll-1 die-1) (insert (format " %4d" (1+ roll-1)))) (newline) (dotimes (roll-2 die-2) (insert (format " %4d" (1+ roll-2))) (dotimes (roll-1 die-1) (insert " " (cond ((> roll-1 roll-2) (incf a) "A") ((= roll-1 roll-2) (incf n) "-") (t (incf b) "B")))) (newline)) (newline) (let ((total (+ a b n))) (insert (format "A: %d / %d = %4.3f\n" a total (/ a 1.0 total))) (insert (format "B: %d / %d = %4.3f\n" b total (/ b 1.0 total))) (insert (format "-: %d / %d = %4.3f\n" n total (/ n 1.0 total)))) (newline) (newline))))) d4 vs. d4 1 2 3 4 1 - A A A 2 B - A A 3 B B - A 4 B B B - A: 6 / 16 = 0.375 B: 6 / 16 = 0.375 -: 4 / 16 = 0.250 d4 vs. d6 1 2 3 4 1 - A A A 2 B - A A 3 B B - A 4 B B B - 5 B B B B 6 B B B B A: 6 / 24 = 0.250 B: 14 / 24 = 0.583 -: 4 / 24 = 0.167 d4 vs. d8 1 2 3 4 1 - A A A 2 B - A A 3 B B - A 4 B B B - 5 B B B B 6 B B B B 7 B B B B 8 B B B B A: 6 / 32 = 0.188 B: 22 / 32 = 0.688 -: 4 / 32 = 0.125 d4 vs. d10 1 2 3 4 1 - A A A 2 B - A A 3 B B - A 4 B B B - 5 B B B B 6 B B B B 7 B B B B 8 B B B B 9 B B B B 10 B B B B A: 6 / 40 = 0.150 B: 30 / 40 = 0.750 -: 4 / 40 = 0.100 d4 vs. d12 1 2 3 4 1 - A A A 2 B - A A 3 B B - A 4 B B B - 5 B B B B 6 B B B B 7 B B B B 8 B B B B 9 B B B B 10 B B B B 11 B B B B 12 B B B B A: 6 / 48 = 0.125 B: 38 / 48 = 0.792 -: 4 / 48 = 0.083 d6 vs. d6 1 2 3 4 5 6 1 - A A A A A 2 B - A A A A 3 B B - A A A 4 B B B - A A 5 B B B B - A 6 B B B B B - A: 15 / 36 = 0.417 B: 15 / 36 = 0.417 -: 6 / 36 = 0.167 d6 vs. d8 1 2 3 4 5 6 1 - A A A A A 2 B - A A A A 3 B B - A A A 4 B B B - A A 5 B B B B - A 6 B B B B B - 7 B B B B B B 8 B B B B B B A: 15 / 48 = 0.312 B: 27 / 48 = 0.562 -: 6 / 48 = 0.125 d6 vs. d10 1 2 3 4 5 6 1 - A A A A A 2 B - A A A A 3 B B - A A A 4 B B B - A A 5 B B B B - A 6 B B B B B - 7 B B B B B B 8 B B B B B B 9 B B B B B B 10 B B B B B B A: 15 / 60 = 0.250 B: 39 / 60 = 0.650 -: 6 / 60 = 0.100 d6 vs. d12 1 2 3 4 5 6 1 - A A A A A 2 B - A A A A 3 B B - A A A 4 B B B - A A 5 B B B B - A 6 B B B B B - 7 B B B B B B 8 B B B B B B 9 B B B B B B 10 B B B B B B 11 B B B B B B 12 B B B B B B A: 15 / 72 = 0.208 B: 51 / 72 = 0.708 -: 6 / 72 = 0.083 d8 vs. d8 1 2 3 4 5 6 7 8 1 - A A A A A A A 2 B - A A A A A A 3 B B - A A A A A 4 B B B - A A A A 5 B B B B - A A A 6 B B B B B - A A 7 B B B B B B - A 8 B B B B B B B - A: 28 / 64 = 0.438 B: 28 / 64 = 0.438 -: 8 / 64 = 0.125 d8 vs. d10 1 2 3 4 5 6 7 8 1 - A A A A A A A 2 B - A A A A A A 3 B B - A A A A A 4 B B B - A A A A 5 B B B B - A A A 6 B B B B B - A A 7 B B B B B B - A 8 B B B B B B B - 9 B B B B B B B B 10 B B B B B B B B A: 28 / 80 = 0.350 B: 44 / 80 = 0.550 -: 8 / 80 = 0.100 d8 vs. d12 1 2 3 4 5 6 7 8 1 - A A A A A A A 2 B - A A A A A A 3 B B - A A A A A 4 B B B - A A A A 5 B B B B - A A A 6 B B B B B - A A 7 B B B B B B - A 8 B B B B B B B - 9 B B B B B B B B 10 B B B B B B B B 11 B B B B B B B B 12 B B B B B B B B A: 28 / 96 = 0.292 B: 60 / 96 = 0.625 -: 8 / 96 = 0.083 d10 vs. d10 1 2 3 4 5 6 7 8 9 10 1 - A A A A A A A A A 2 B - A A A A A A A A 3 B B - A A A A A A A 4 B B B - A A A A A A 5 B B B B - A A A A A 6 B B B B B - A A A A 7 B B B B B B - A A A 8 B B B B B B B - A A 9 B B B B B B B B - A 10 B B B B B B B B B - A: 45 / 100 = 0.450 B: 45 / 100 = 0.450 -: 10 / 100 = 0.100 d10 vs. d12 1 2 3 4 5 6 7 8 9 10 1 - A A A A A A A A A 2 B - A A A A A A A A 3 B B - A A A A A A A 4 B B B - A A A A A A 5 B B B B - A A A A A 6 B B B B B - A A A A 7 B B B B B B - A A A 8 B B B B B B B - A A 9 B B B B B B B B - A 10 B B B B B B B B B - 11 B B B B B B B B B B 12 B B B B B B B B B B A: 45 / 120 = 0.375 B: 65 / 120 = 0.542 -: 10 / 120 = 0.083 d12 vs. d12 1 2 3 4 5 6 7 8 9 10 11 12 1 - A A A A A A A A A A A 2 B - A A A A A A A A A A 3 B B - A A A A A A A A A 4 B B B - A A A A A A A A 5 B B B B - A A A A A A A 6 B B B B B - A A A A A A 7 B B B B B B - A A A A A 8 B B B B B B B - A A A A 9 B B B B B B B B - A A A 10 B B B B B B B B B - A A 11 B B B B B B B B B B - A 12 B B B B B B B B B B B - A: 66 / 144 = 0.458 B: 66 / 144 = 0.458 -: 12 / 144 = 0.083
#Emacs #RPG
(Please contact me if you want to remove your comment.)
⁂
I thought you drew the visualizations by hand. I didn’t think your little piece of Lisp code drew them. Three cheers for simulations with Lisp!
– Aaron S. Hawley 2014-06-24 23:05 UTC
---
Thanks. 😄
– Alex Schroeder 2014-06-25 10:05 UTC