Skip to content

Instantly share code, notes, and snippets.

@whostolebenfrog
Created November 8, 2012 14:11
Show Gist options
  • Save whostolebenfrog/4039018 to your computer and use it in GitHub Desktop.
Save whostolebenfrog/4039018 to your computer and use it in GitHub Desktop.
Secret santa
(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