Skip to content

Instantly share code, notes, and snippets.

@freelon
Created August 2, 2022 18:37
Show Gist options
  • Save freelon/db82590169c108d87729a338fd173c67 to your computer and use it in GitHub Desktop.
Save freelon/db82590169c108d87729a338fd173c67 to your computer and use it in GitHub Desktop.
Comparison of roll probabilities for different dice sets
(ns foo.dice-roll-comparison)
(def roll-1d20 (for [i (range 1 21)] i))
(def roll-median-3d20 (for [a (range 1 21) b (range 1 21) c (range 1 21)] (second (sort (list a b c)))))
(def roll-sum-3d6 (for [a (range 1 7) b (range 1 7) c (range 1 7)] (+ a b c)))
(def roll-sum-2d10 (for [a (range 1 11) b (range 1 11)] (+ a b)))
(defn probabilities [values] (into (sorted-map) (update-vals (frequencies values) (fn [i] (/ (* i 100.0) (count values))))))
(doseq [[x y] (seq (probabilities roll1d20))] (println x y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment