Created
November 8, 2012 14:11
-
-
Save whostolebenfrog/4039018 to your computer and use it in GitHub Desktop.
Secret santa
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
(ns secret-santa.core | |
(require [clojure.set :refer [difference]])) | |
;; note: only works if each person is in a single constraint | |
(def people #{:carole :ben :andrew :hillary :tom :dick :harry :barry}) | |
(def constraints '([:carole :ben] [:andrew :hillary])) | |
(defn split | |
[people] | |
(let [constrained (flatten constraints) | |
list (apply conj constrained (difference people (set constrained))) | |
split-list (apply interleave (split-at (/ (count list) 2) list))] | |
(apply conj | |
[[(last split-list) (first split-list)]] | |
(for [[a b] (partition 2 1 split-list)] | |
[a b])))) | |
(split people) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment