tangled
alpha
login
or
join now
m1emi1em.dev
/
aoc2025
1
fork
atom
this repo has no description
1
fork
atom
overview
issues
pulls
pipelines
(D4P1): Solution
m1emi1em.dev
3 months ago
cae63b84
ef59b652
+46
2 changed files
expand all
collapse all
unified
split
resources
04-test.txt
src
aoc2025
day4.clj
+10
resources/04-test.txt
···
1
1
+
..@@.@@@@.
2
2
+
@@@.@.@.@@
3
3
+
@@@@@.@.@@
4
4
+
@.@@@@..@.
5
5
+
@@.@@@@.@@
6
6
+
.@@@@@@@.@
7
7
+
.@.@.@.@@@
8
8
+
@.@@@.@@@@
9
9
+
.@@@@@@@@.
10
10
+
@.@.@@@.@.
+36
src/aoc2025/day4.clj
···
1
1
+
(ns aoc2024.day4
2
2
+
(:require [aoc2025.util :as util]
3
3
+
[clojure.string :as str]))
4
4
+
5
5
+
(defn- parse-file [fname]
6
6
+
(->> fname util/read-file util/gridify))
7
7
+
8
8
+
(defn- part1 [grid]
9
9
+
(let [height (-> grid count)
10
10
+
width (-> grid first count)
11
11
+
paper? (partial = \@)]
12
12
+
(count
13
13
+
(for [idy (range height)
14
14
+
idx (range width)
15
15
+
:let [pos [idy idx]
16
16
+
cell (get-in grid pos)
17
17
+
adjacent-cells (->> pos util/adj+
18
18
+
(filter #(every? (util/between? 0 (dec width)) %))
19
19
+
(map #(get-in grid %)))
20
20
+
adjacent-paper-count (->> adjacent-cells (filter paper?) count)]
21
21
+
:when
22
22
+
(and (paper? cell)
23
23
+
(< adjacent-paper-count 4))]
24
24
+
pos))))
25
25
+
26
26
+
(defn- part2 [grid])
27
27
+
28
28
+
(defn solve
29
29
+
([] (solve "04.txt"))
30
30
+
([fname]
31
31
+
(->> (parse-file fname) ((juxt part1 part2)))))
32
32
+
33
33
+
(solve "04-test.txt")
34
34
+
35
35
+
(solve) ; => 1363
36
36
+