frequencies in Clojure 1 minute read Notes clj꞉user꞉> (frequencies [:a :a :b :a :c :b]) {:a 3, :b 2, :c 1} clj꞉user꞉> (for [x (range 6) y (range 6)] (list x y)) ((0 0) (0 1) (0 2) (0 3) (0 4) (0 5) (1 0) (1 1) (1 2) (1 3) (1 4) (1 5) (2 0) (2 1) (2 2) (2 3) (2 4) (2 5) (3 0) (3 1) (3 2) (3 3) (3 4) (3 5) (4 0) (4 1) (4 2) (4 3) (4 4) (4 5) (5 0) (5 1) (5 2) (5 3) (5 4) (5 5)) clj꞉user꞉> (for [x (range 6) y (range 6)] (+ x y)) (0 1 2 3 4 5 1 2 3 4 5 6 2 3 4 5 6 7 3 4 5 6 7 8 4 5 6 7 8 9 5 6 7 8 9 10) clj꞉user꞉> (for [x (range 6) y (range 6)] (+ x y 2)) (2 3 4 5 6 7 3 4 5 6 7 8 4 5 6 7 8 9 5 6 7 8 9 10 6 7 8 9 10 11 7 8 9 10 11 12) clj꞉user꞉> (frequencies (for [x (range 6) y (range 6)] (+ x y 2))) {7 6, 4 3, 6 5, 3 2, 12 1, 2 1, 11 2, 9 4, 5 4, 10 3, 8 5} Histogram from sum of throw of dice pair using Clojure frequencies Twitter Facebook LinkedIn Previous Next