Compare commits
2 Commits
5ef8f4af1d
...
bdd2a03230
| Author | SHA1 | Date | |
|---|---|---|---|
| bdd2a03230 | |||
| 8695b8b375 |
@ -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
41
src/day11.clj
Normal 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!"))
|
||||
Loading…
x
Reference in New Issue
Block a user