File tree 2 files changed +81
-0
lines changed
2 files changed +81
-0
lines changed Original file line number Diff line number Diff line change
1
+ (ns y2024.d25
2
+ (:require
3
+ [advent-of-code-clj.input :as input]
4
+ [advent-of-code-clj.utils :as utils]
5
+ [com.rpl.specter :as s]))
6
+
7
+ (def test-input " #####
8
+ .####
9
+ .####
10
+ .####
11
+ .#.#.
12
+ .#...
13
+ .....
14
+
15
+ #####
16
+ ##.##
17
+ .#.##
18
+ ...##
19
+ ...#.
20
+ ...#.
21
+ .....
22
+
23
+ .....
24
+ #....
25
+ #....
26
+ #...#
27
+ #.#.#
28
+ #.###
29
+ #####
30
+
31
+ .....
32
+ .....
33
+ #.#..
34
+ ###..
35
+ ###.#
36
+ ###.#
37
+ #####
38
+
39
+ .....
40
+ .....
41
+ .....
42
+ #....
43
+ #.#..
44
+ #.#.#
45
+ #####" )
46
+
47
+ (def example-key " .....
48
+ .....
49
+ .....
50
+ #....
51
+ #.#..
52
+ #.#.#
53
+ #####" )
54
+
55
+ (defn parse-key [input]
56
+ (map (fn [line]
57
+ (dec (count (filter #{\.} line))))
58
+ (apply mapv vector (utils/text->matrix input))))
59
+ (defn parse-lock [input]
60
+ (map (fn [line]
61
+ (dec (count (filter #{\#} line))))
62
+ (apply mapv vector (utils/text->matrix input))))
63
+
64
+ (defn parse [input]
65
+ (let [lock-or-key (.split input " \n\n " )
66
+ lock (filter #(.startsWith % " #####" ) lock-or-key)
67
+ key (remove #(.startsWith % " #####" ) lock-or-key)]
68
+ {:keys (map parse-key key)
69
+ :locks (map parse-lock lock)}))
70
+
71
+ (defn part-1 [input]
72
+ (let [{:keys [locks keys]} (parse input)]
73
+ (count (for [key keys
74
+ lock locks
75
+ :let [subbed (map - key lock)]
76
+ :when (every? nat-int? subbed)]
77
+ subbed))))
78
+
79
+ (part-1 test-input)
80
+
81
+ (part-1 (input/get-input 2024 25 ))
You can’t perform that action at this time.
0 commit comments