mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 05:23:17 -09:00
init day 10
This commit is contained in:
parent
c2f421cc03
commit
a09033eaff
50
2024/input/10.txt
Normal file
50
2024/input/10.txt
Normal file
@ -0,0 +1,50 @@
|
||||
01210565345898676589898782365821232102010123017876
|
||||
90321678216787789432765691078910123421129898326921
|
||||
85434589307675692321054302169891436530234787635410
|
||||
76105410898365781010303213456786569645345676544321
|
||||
85234323965414654325212300145652478756764980121010
|
||||
99965410879303109834567810234521010189893210236789
|
||||
78876323478212236723654923210433125670120189845678
|
||||
67891274560143445210543214541244534561431276796012
|
||||
54900785123432212347652905610143213432587345687323
|
||||
03215691098501101458921876921658701521696014987432
|
||||
12104320187632310762340967834769657610785223896561
|
||||
89001211290547499891056754965892348901234106767870
|
||||
78701004321678987012349823876101637878789015458987
|
||||
57632985934554356101067810732876578769654320327810
|
||||
66543876821765243241056934541923459054754321216721
|
||||
76544710730890154332343129690012365149869210205430
|
||||
89235623649212343451010018781011076232778900124321
|
||||
89126104558901650142161209652100985401657635433567
|
||||
76011234567230789233454313443001234300344521589458
|
||||
69800101010147898541969896323121201211235430676329
|
||||
54763212327656987680878765410010340125656780034210
|
||||
03454987438705467891253267651103456234743491125876
|
||||
12565898549812356732344198543212187649872332976945
|
||||
23476787653201345673445053434781098521011349889932
|
||||
10984323654101230984986764325690678434100656779871
|
||||
06765014787010121895679871014506589847812341018760
|
||||
19854565498321030765098762123417432156998765123454
|
||||
87763474325441001234125634564328921034567654104303
|
||||
96012981016932018983034521071012980103010783210412
|
||||
05692345697849823676123658989343898912023890104321
|
||||
14581016787856704589105437210956769820124730032450
|
||||
23673451078933219673216926367801458765435621121267
|
||||
10562162564324788764567815450132349654596534230398
|
||||
21093073455015691058766701321891212563187965495434
|
||||
38981989526998582349654877894580305012056876786543
|
||||
47670676017877894321123966943671456872146781787012
|
||||
56541905423456765890001455432106567987235690195401
|
||||
65432812332303456789010340321017898716544303276513
|
||||
76306701221412309654321231298543410106983210389432
|
||||
89215412030565218943289101067652341237803454459011
|
||||
50300303121674307650176532356501496546712365598120
|
||||
41101254438985456210125901445032587435012879687034
|
||||
32256965567676781032134876532145670124326978776543
|
||||
43347871298767892345092180123230598763065857894304
|
||||
56998780185652102216783091038321347892176543765212
|
||||
47882398234543221003234582549801256743089434894301
|
||||
30701543210956310120107698756703454656910125323212
|
||||
21032672341865210032198989687012563347887016714509
|
||||
32147881256774398941099012596549872210996509803678
|
||||
43456990165789787656787103401234901300123418712101
|
@ -27,6 +27,12 @@
|
||||
col (range (count (get list-of-lists row)))]
|
||||
[row col]))
|
||||
|
||||
(defn map-by-coords [arr-2d]
|
||||
(->> arr-2d
|
||||
get-coords
|
||||
(map (juxt identity #(get (get arr-2d (first %)) (second %))))
|
||||
(into {})))
|
||||
|
||||
(defn insert-at-idx [coll idx el]
|
||||
(concat (take idx coll)
|
||||
(list el)
|
||||
|
56
2024/src/day10.clj
Normal file
56
2024/src/day10.clj
Normal file
@ -0,0 +1,56 @@
|
||||
(ns day10
|
||||
(:require [core :as c]
|
||||
[input-manager :refer [get-input]]))
|
||||
|
||||
(def input (update-vals (c/map-by-coords (get-input 10))
|
||||
#(Character/getNumericValue %)))
|
||||
|
||||
(def trailheads (->> input
|
||||
(filter #(= 0 (second %)))
|
||||
(map first)))
|
||||
|
||||
(defn possible-steps [loc]
|
||||
(let [c (input loc)]
|
||||
(->> [(update loc 0 inc)
|
||||
(update loc 0 dec)
|
||||
(update loc 1 inc)
|
||||
(update loc 1 dec)]
|
||||
(filter #(= (input %) (inc c))))))
|
||||
|
||||
(defn get-score [trailhead]
|
||||
(->> (loop [[loc & locs] [trailhead]
|
||||
seen #{trailhead}]
|
||||
(if (nil? loc)
|
||||
seen
|
||||
(let [steps (filter (comp not seen)
|
||||
(possible-steps loc))]
|
||||
(recur (into locs steps)
|
||||
(into seen steps)))))
|
||||
(filter #(= 9 (input %)))
|
||||
count))
|
||||
|
||||
;; part 1
|
||||
(->> trailheads
|
||||
(map get-score)
|
||||
(reduce +))
|
||||
|
||||
(defn get-trails [trailhead]
|
||||
(->> (loop [[[loc path] & locs] [[trailhead []]]
|
||||
trails #{}]
|
||||
(cond
|
||||
(nil? loc) trails
|
||||
|
||||
(= (input loc) 9)
|
||||
(recur locs (conj trails path))
|
||||
|
||||
:else
|
||||
(let [steps (map (juxt identity #(conj path %))
|
||||
(possible-steps loc))]
|
||||
(recur (into locs steps)
|
||||
trails))))))
|
||||
|
||||
;; part 2
|
||||
(->> trailheads
|
||||
(map get-trails)
|
||||
(map count)
|
||||
(reduce +))
|
Loading…
x
Reference in New Issue
Block a user