Skip to content

Instantly share code, notes, and snippets.

@Timo-Linde
Last active November 10, 2021 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Timo-Linde/21717bb8197bc74738037402d477ddfa to your computer and use it in GitHub Desktop.
Save Timo-Linde/21717bb8197bc74738037402d477ddfa to your computer and use it in GitHub Desktop.
Secret Santa
(ns website.wichtel)
(def teilnehmer:innen
#{"Alex" "Alina" "Andrea" "Chris" "Justine" "Pia" "Timo" "Volker"})
(def paare
[#{"Alex" "Alina"}
#{"Andrea" "Volker"}
#{"Chris" "Pia"}
#{"Justine" "Timo"}])
(defn ist-partner-von?
[teilnehmer-1 teilnehmer-2]
(contains?
(->> paare
(filter #(contains? % teilnehmer-1))
(first))
teilnehmer-2))
(defn- zuordnen
[teilnehmer:innen]
(->> teilnehmer:innen
(shuffle)
(cycle)
(take (inc (count teilnehmer:innen)))
(partition 2 1)))
(defn- paar-zugeordnet?
[[teilnehmer-1 teilnehmer-2]]
(ist-partner-von? teilnehmer-1 teilnehmer-2))
(defn output-zuordnung
[[teilnehmer-1 teilnehmer-2]]
(spit
(str "/Users/linde/playground/secret-santa/" teilnehmer-1 ".txt")
(str "Hallo " teilnehmer-1 " du hast für das Wichteln den Teilnehmer " teilnehmer-2 " gezogen.")))
(defn auslosen
[teilnehmer:innen]
(let [zuordnungen (zuordnen teilnehmer:innen)]
(if (some true? (map paar-zugeordnet? zuordnungen))
(do (println "paar zugeordnet... noch ein versuch")
(auslosen teilnehmer:innen))
(dorun (map output-zuordnung zuordnungen)))))
(auslosen teilnehmer:innen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment