aboutsummaryrefslogtreecommitdiffstats
path: root/year2021/day21/part1.clj
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
committerClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
commit8d43e37df99f280377bed90284d6ac2428334804 (patch)
tree3a5042c9af29da52b4bac38fd78b3ccde77a1dbc /year2021/day21/part1.clj
parent66ed0b9d27850dc653abc8baa75884f3de311bfa (diff)
move 2021 days to folder; update README
Diffstat (limited to 'year2021/day21/part1.clj')
-rw-r--r--year2021/day21/part1.clj22
1 files changed, 22 insertions, 0 deletions
diff --git a/year2021/day21/part1.clj b/year2021/day21/part1.clj
new file mode 100644
index 0000000..174f5a1
--- /dev/null
+++ b/year2021/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)))))
+