Skip to content

Commit 3cdb244

Browse files
committed
2016 24
1 parent b2895e9 commit 3cdb244

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/advent_of_code/2016/24.clj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
(ns advent-of-code.2016.24
2+
(:require [advent-of-code.utils :as u]
3+
[advent-of-code.points :as p]
4+
[advent-of-code.vectors :refer [evict-at]]))
5+
6+
(def path (u/get-input 2016 24))
7+
(def tpath (u/test-path 2016 24))
8+
9+
; Incredibly slow, but I'm lazy today, and it works, so why bother ¯\_(ツ)_/¯
10+
(defn run [path part2?]
11+
(let [grid (->> (u/read-file-list path identity)
12+
p/->grid)
13+
start (ffirst (filter #(#{\0} (second %)) grid))
14+
targets (->> (filter #(#{\1 \2 \3 \4 \5 \6 \7 \8 \9} (second %)) grid)
15+
(mapv first))
16+
min-path (fn bfs [curr open]
17+
(if (empty? open)
18+
(if part2? (p/a-star-score grid curr start) 0)
19+
(apply min (map (fn [i] (+ (p/a-star-score grid curr (open i))
20+
(bfs (open i) (evict-at open i)))) (range (count open))))))]
21+
(time (min-path start targets))))
22+
23+
(comment
24+
25+
(run path false)
26+
(run path true)
27+
;
28+
)

0 commit comments

Comments
 (0)