aboutsummaryrefslogtreecommitdiffstats
path: root/day21
diff options
context:
space:
mode:
Diffstat (limited to 'day21')
-rw-r--r--day21/part1.clj22
-rw-r--r--day21/part2.clj37
2 files changed, 0 insertions, 59 deletions
diff --git a/day21/part1.clj b/day21/part1.clj
deleted file mode 100644
index 174f5a1..0000000
--- a/day21/part1.clj
+++ /dev/null
@@ -1,22 +0,0 @@
-(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)))))
-
diff --git a/day21/part2.clj b/day21/part2.clj
deleted file mode 100644
index 0042aaa..0000000
--- a/day21/part2.clj
+++ /dev/null
@@ -1,37 +0,0 @@
-(defn dice-probability-spread [sides rolls]
- (let [sr (range 1 (inc sides))]
- (->> sr
- (iterate #(flatten (for [i sr] (map (partial + i) %))))
- (drop (dec rolls))
- ((comp frequencies first)))))
-
-(def rolls (dice-probability-spread 3 3))
-
-(defn advance-pos [pos roll] (let [n (+ pos roll)] (if (> n 10) (- n 10) n)))
-
-(defn add-roll [state roll p1-turn]
- (let [pos (if p1-turn :pos1 :pos2)
- score (if p1-turn :score1 :score2)
- new-pos (advance-pos (state pos) roll)]
- (-> state
- (assoc pos new-pos)
- (update score + new-pos))))
-
-(defonce wins (atom [0 0]))
-
-(loop [turn 0 states {{:pos1 4 :score1 0 :pos2 8 :score2 0} 1}]
- (if (empty? states)
- (println (apply max @wins))
- (recur
- (if (= 0 turn) 1 0)
- (reduce
- #(let [kvp (first %2)]
- (if (< ((key kvp) (if (= 0 turn) :score1 :score2)) 21)
- (if (contains? %1 (key kvp))
- (update %1 (key kvp) +' (val kvp))
- (conj %1 kvp))
- (do (swap! wins update turn +' (val kvp)) %1)))
- {}
- (for [s states r rolls]
- {(add-roll (first s) (key r) (= 0 turn)) (*' (second s) (val r))})))))
-