From 384079cb4dd4499d50ca17d1ee4fdd8dafdcd79b Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 21 Dec 2021 13:00:36 -0500 Subject: [PATCH] day21: add part 1 --- day21/part1.clj | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 day21/part1.clj diff --git a/day21/part1.clj b/day21/part1.clj new file mode 100644 index 0000000..174f5a1 --- /dev/null +++ b/day21/part1.clj @@ -0,0 +1,22 @@ +(require 'clojure.string) + +(loop [player-positions (->> (slurp "./in") + clojure.string/split-lines + (map (comp read-string second #(clojure.string/split % #": "))) + (mapv #(drop (dec %) (cycle (range 1 11))))) + player-scores (into [] (repeat (count player-positions) 0)) + player-turn (cycle (range 0 (count player-scores))) + deterministic-dice (cycle (range 1 101)) + dice-roll-count 0] + (if-not (every? #(< % 1000) player-scores) + (println (* dice-roll-count (apply min player-scores))) + (let [roll (reduce + (take 3 deterministic-dice)) + turn (first player-turn) + new-position (drop roll (get player-positions turn))] + (recur + (assoc player-positions turn new-position) + (update player-scores turn + (first new-position)) + (next player-turn) + (drop 3 deterministic-dice) + (+ dice-roll-count 3))))) +