Compare commits
2 Commits
8ff632503f
...
1087a7649b
| Author | SHA1 | Date | |
|---|---|---|---|
| 1087a7649b | |||
| 5077215205 |
@@ -0,0 +1,30 @@
|
|||||||
|
(ns day05
|
||||||
|
(:require input-manager))
|
||||||
|
|
||||||
|
(def input (->> (input-manager/get-input 2017 5)
|
||||||
|
(mapv parse-long)))
|
||||||
|
|
||||||
|
(def MAX_IDX (count input))
|
||||||
|
|
||||||
|
;; part 1
|
||||||
|
(loop [steps 0
|
||||||
|
maze input
|
||||||
|
idx 0]
|
||||||
|
(let [maze' (update maze idx inc)
|
||||||
|
idx' (+ (maze idx) idx)]
|
||||||
|
(if (< -1 idx' MAX_IDX)
|
||||||
|
(recur (inc steps) maze' idx')
|
||||||
|
(inc steps))))
|
||||||
|
|
||||||
|
;; part 2
|
||||||
|
(loop [steps 0
|
||||||
|
maze input
|
||||||
|
idx 0]
|
||||||
|
(let [offset (maze idx)
|
||||||
|
maze' (update maze idx (if (>= offset 3)
|
||||||
|
dec
|
||||||
|
inc))
|
||||||
|
idx' (+ offset idx)]
|
||||||
|
(if (< -1 idx' MAX_IDX)
|
||||||
|
(recur (inc steps) maze' idx')
|
||||||
|
(inc steps))))
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
(ns day06
|
||||||
|
(:require [input-manager]
|
||||||
|
[core :refer [split-whitespace]]))
|
||||||
|
|
||||||
|
(def input
|
||||||
|
(->> (input-manager/get-input-raw 2017 6)
|
||||||
|
split-whitespace
|
||||||
|
(mapv parse-long)))
|
||||||
|
|
||||||
|
(loop [state input
|
||||||
|
i 0
|
||||||
|
seen {}]
|
||||||
|
(if (contains? seen state)
|
||||||
|
{:part-one i
|
||||||
|
:part-two (- i (seen state))}
|
||||||
|
(let [cnt (apply max state)
|
||||||
|
idx (->> state
|
||||||
|
(map-indexed vector)
|
||||||
|
(filter #(= (second %) cnt))
|
||||||
|
ffirst)]
|
||||||
|
(recur (->> (range cnt)
|
||||||
|
(map #(mod (+ idx 1 %) (count state)))
|
||||||
|
(reduce #(update %1 %2 inc) (assoc state idx 0)))
|
||||||
|
(inc i)
|
||||||
|
(assoc seen state i)))))
|
||||||
|
|
||||||
Reference in New Issue
Block a user