Created
May 12, 2016 13:03
-
-
Save nathell/0c308896b7c8ce329ab9af05a88182e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; A Clojure implementation of http://koziolekweb.pl/2016/05/08/lotto-to-fajna-rzecz/. | |
(ns lotto) | |
(defn lotto | |
([] (lotto 49 6 100000)) | |
([n k r] | |
(let [balls (range 1 (inc n)) | |
random-balls #(take k (shuffle balls)) | |
empty-counts (zipmap balls (repeat 0)) | |
append-counts (fn [counts draw] | |
(reduce #(update-in %1 [%2] inc) counts draw)) | |
counts (reduce append-counts empty-counts (repeatedly r random-balls))] | |
(println counts) | |
(doseq [[b v] (sort-by val counts)] | |
(printf "%d=%.2f%%\n" b (/ (* 100.0 v) r)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment