Skip to content

Instantly share code, notes, and snippets.

@nathell
Created May 12, 2016 13:03
Show Gist options
  • Save nathell/0c308896b7c8ce329ab9af05a88182e6 to your computer and use it in GitHub Desktop.
Save nathell/0c308896b7c8ce329ab9af05a88182e6 to your computer and use it in GitHub Desktop.
;; 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