Histogram from sum of throw of dice pair using Clojure
Notes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
;; dice_histogram.clj
(def faces (range 1 (inc 6)))
(def permutations
(for
[x faces
y faces]
(list x y)))
(defn sum [a b] (+ a b))
(def sum-of-throws (map #(sum (first %) (last %)) permutations))
(count (filter #(= % 7) sum-of-throws))
(doseq
[sum (range 2 (inc 12))]
(println sum " => " (count (filter #(= % sum) sum-of-throws))))