mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-11-27 11:32:45 -10:00
simplify
This commit is contained in:
parent
b2339a21a6
commit
f7b77d4fd0
@ -1,24 +1,8 @@
|
|||||||
(ns day20
|
(ns day20
|
||||||
(:require
|
(:require
|
||||||
[core :as c]
|
|
||||||
input-manager))
|
input-manager))
|
||||||
|
|
||||||
(def maze (input-manager/get-input 2024 20)
|
(def maze (input-manager/get-input 2024 20))
|
||||||
#_(c/split-whitespace "###############
|
|
||||||
#...#...#.....#
|
|
||||||
#.#.#.#.#.###.#
|
|
||||||
#S#...#.#.#...#
|
|
||||||
#######.#.#.###
|
|
||||||
#######.#.#...#
|
|
||||||
#######.#.###.#
|
|
||||||
###..E#...#...#
|
|
||||||
###.#######.###
|
|
||||||
#...###...#...#
|
|
||||||
#.#####.#.###.#
|
|
||||||
#.#...#.#.#...#
|
|
||||||
#.#.#.#.#.#.###
|
|
||||||
#...#...#...###
|
|
||||||
###############"))
|
|
||||||
(def grid (->> maze
|
(def grid (->> maze
|
||||||
(map-indexed (fn [row-idx row]
|
(map-indexed (fn [row-idx row]
|
||||||
(map-indexed (fn [col-idx c]
|
(map-indexed (fn [col-idx c]
|
||||||
@ -26,12 +10,12 @@
|
|||||||
row)))
|
row)))
|
||||||
(mapcat identity)
|
(mapcat identity)
|
||||||
(into {})))
|
(into {})))
|
||||||
(def start (->> grid
|
(defn find-char [c]
|
||||||
(filter (comp #{\S} second))
|
(->> grid
|
||||||
ffirst))
|
(filter (comp #{c} second))
|
||||||
(def end (->> grid
|
ffirst))
|
||||||
(filter (comp #{\E} second))
|
(def start (find-char \S))
|
||||||
ffirst))
|
(def end (find-char \E))
|
||||||
|
|
||||||
(def direction-offsets #{[0 1] [1 0] [0 -1] [-1 0]})
|
(def direction-offsets #{[0 1] [1 0] [0 -1] [-1 0]})
|
||||||
|
|
||||||
@ -39,10 +23,8 @@
|
|||||||
(loop [[[pos steps] & rst] [[start 0]]
|
(loop [[[pos steps] & rst] [[start 0]]
|
||||||
visited #{start}
|
visited #{start}
|
||||||
shortest {start 0}]
|
shortest {start 0}]
|
||||||
(cond
|
(if (= pos end)
|
||||||
(= pos end) shortest
|
shortest
|
||||||
|
|
||||||
:else
|
|
||||||
(let [searches (->> direction-offsets
|
(let [searches (->> direction-offsets
|
||||||
(map (partial mapv + pos))
|
(map (partial mapv + pos))
|
||||||
(filter grid)
|
(filter grid)
|
||||||
@ -55,7 +37,6 @@
|
|||||||
|
|
||||||
(defn find-best-cheat []
|
(defn find-best-cheat []
|
||||||
(let [search-path (find-search-path)
|
(let [search-path (find-search-path)
|
||||||
; no-cheat-solution (search-path end)
|
|
||||||
walls (->> grid
|
walls (->> grid
|
||||||
(filter (comp #{\#} second))
|
(filter (comp #{\#} second))
|
||||||
(map first))
|
(map first))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user