day 11 part 1
This commit is contained in:
parent
5ef8f4af1d
commit
8695b8b375
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