Skip to content

Instantly share code, notes, and snippets.

@fogus
Last active April 7, 2025 15:08
Show Gist options
  • Save fogus/4b73cceec36b3ac009a27dc907e9b961 to your computer and use it in GitHub Desktop.
Save fogus/4b73cceec36b3ac009a27dc907e9b961 to your computer and use it in GitHub Desktop.
(defn range-3d6
"A function to return the possible rolls with 3d6 between start and end inclusive."
([n] (list n))
([start end]
(for [d100s (range 1 7)
d10s (range 1 7)
d1s (range 1 7)
:let [num (+ (* 100 d100s) (* 10 d10s) d1s)]
:when (and (<= start num) (<= num end))]
num)))
(range-3d6 111 666)
;;=> (111 112 ... 665 666)
(range-3d6 111)
;;=> (111)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment