Skip to content

Instantly share code, notes, and snippets.

@athos
Created June 16, 2016 03:18
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 athos/491cc22859986e37c29e29037bcb8548 to your computer and use it in GitHub Desktop.
Save athos/491cc22859986e37c29e29037bcb8548 to your computer and use it in GitHub Desktop.
(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