Created
June 16, 2016 03:18
-
-
Save athos/491cc22859986e37c29e29037bcb8548 to your computer and use it in GitHub Desktop.
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
(def players | |
(->> (repeatedly #(read *in* false nil)) | |
(take-while identity) | |
(map-indexed #(vector % ('{J 11 Q 12 K 13 A 14 2 15} %2 %2))) | |
(into clojure.lang.PersistentQueue/EMPTY))) | |
(defn solve [ps] | |
(loop [[[id n :as p] :as ps] ps, card nil, passes 0, winners []] | |
(cond (empty? ps) winners | |
(= passes (count ps)) (recur ps nil 0 winners) | |
(or (nil? card) (> n card)) (recur (pop ps) n 0 (conj winners id)) | |
:else (recur (conj (pop ps) p) card (inc passes) winners)))) | |
(doseq [[_ i] (sort-by key (zipmap (solve players) (range)))] | |
(println (inc i))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment