Created
December 6, 2014 18:32
-
-
Save mwmitchell/7569f28b3f5ac9538fdc to your computer and use it in GitHub Desktop.
xmas gift swap
This file contains 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
(require '[clojure.string :as str]) | |
(require '[clojure.set :as set]) | |
(require '[clojure.pprint :as pp]) | |
(defn map-names [names] | |
(first | |
(reduce | |
(fn [mem n1] | |
(let [avail (set/difference names (get mem 1)) | |
sel (->> avail shuffle (some #(when (not= n1 %1) %1)))] | |
(-> mem | |
(assoc-in [0 n1] sel) | |
(update-in [1] conj sel)))) | |
[{} #{}] names))) | |
(pp/pprint (map-names #{"barney" "fred" "wilma" "betty" "pebbles" "dino" "bamm bamm" "baby puss" "hoppy"})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment