mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 09:23:17 -09:00
use cond over nested else if
This commit is contained in:
parent
d40e6cfcd8
commit
bc60e6246b
@ -35,16 +35,15 @@
|
|||||||
(loop [pos start
|
(loop [pos start
|
||||||
dir :up
|
dir :up
|
||||||
path #{}]
|
path #{}]
|
||||||
(if (not (in-bounds? pos))
|
(cond
|
||||||
path
|
(not (in-bounds? pos)) path
|
||||||
(if (path [dir pos])
|
(path [dir pos]) :cycle
|
||||||
:cycle
|
:else (let [pos' (move dir pos)]
|
||||||
(let [pos' (move dir pos)]
|
(if (= (get-char pos') \#)
|
||||||
(if (= (get-char pos') \#)
|
(recur pos (turn-right dir) (conj path [dir pos]))
|
||||||
(recur pos (turn-right dir) (conj path [dir pos]))
|
(recur pos'
|
||||||
(recur pos'
|
dir
|
||||||
dir
|
(conj path [dir pos])))))))
|
||||||
(conj path [dir pos]))))))))
|
|
||||||
|
|
||||||
(defn add-obstacle [[row col]]
|
(defn add-obstacle [[row col]]
|
||||||
(update input row assoc col \#))
|
(update input row assoc col \#))
|
||||||
@ -57,9 +56,9 @@
|
|||||||
|
|
||||||
;; part 2
|
;; part 2
|
||||||
(->> (for [pos (->> (get-path)
|
(->> (for [pos (->> (get-path)
|
||||||
(map second)
|
(map second)
|
||||||
distinct
|
distinct
|
||||||
(filter #(not= % start)))]
|
(filter #(not= % start)))]
|
||||||
(with-redefs [input (add-obstacle pos)] (get-path)))
|
(with-redefs [input (add-obstacle pos)] (get-path)))
|
||||||
(filter #(= % :cycle))
|
(filter #(= % :cycle))
|
||||||
count)
|
count)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user