Last active
November 10, 2021 12:10
-
-
Save Timo-Linde/21717bb8197bc74738037402d477ddfa 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 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