Compare commits

...

2 Commits

Author SHA1 Message Date
bdd2a03230 fixup! day 10 WIP 2024-12-12 21:27:08 +03:00
8695b8b375 day 11 part 1 2024-12-12 21:26:56 +03:00
2 changed files with 65 additions and 5 deletions

View File

@ -3,8 +3,6 @@
[helpers :refer [get-input]]))
(def test-map
(mapped-area/parse-elements
(mapped-area/read-mapped-area
"89010123
78121874
87430965
@ -12,7 +10,19 @@
45678903
32019012
01329801
10456732")))
10456732")
;(def test-map
;"0123
;1234
;8765
;9876")
(def input
(->
test-map
mapped-area/read-mapped-area
mapped-area/parse-elements))
(defn trailheads [a]
(reduce
@ -42,6 +52,15 @@
(count positions)
(recur (mapcat (partial step a) (set positions))))))
(loop [i 0 positions (trailheads input)]
(println "iteration" i)
(doall
(map #(println % "-" (get-in input %)) positions))
(if (== i 9)
positions
(recur (inc i)
(mapcat (partial step input) positions))))
(reduce +
(map (partial walk test-map) (trailheads test-map)))
(trailheads input)
(mapcat (partial step input) (trailheads input))

41
src/day11.clj Normal file
View File

@ -0,0 +1,41 @@
(ns day11
(:require [clojure.string :as string]
[helpers :refer [get-input]]))
(def stones
(string/split
;;"125 17"
(string/trim (get-input 11))
#" "))
(defn split-stone [stone]
(let [ss (split-at
(/ (count stone) 2)
stone)
seq->stone
(fn [s]
(str
(parse-long
(apply str s))))]
(mapv seq->stone ss)))
(defn blink [stone]
(cond
(= stone "0")
["1"]
(even? (count stone))
(split-stone stone)
:else
(vector
(str
(* 2024
(parse-long stone))))))
(time
(println "I blinked 25 times, there's"
(count
(loop [i 0 stones stones]
(if (= 25 i)
stones
(recur (inc i) (mapcat blink stones)))))
"stones!"))