File tree 3 files changed +27
-17
lines changed
3 files changed +27
-17
lines changed Original file line number Diff line number Diff line change 1
1
(ns y2024.d25
2
2
(:require
3
3
[advent-of-code-clj.input :as input]
4
- [advent-of-code-clj.utils :as utils ]))
4
+ [advent-of-code-clj.matrix :as mx ]))
5
5
6
6
(def test-input " #####
7
7
.####
54
54
(defn parse-key [input]
55
55
(map (fn [line]
56
56
(dec (count (filter #{\.} line))))
57
- (apply mapv vector ( utils /text->matrix input))))
57
+ (mx/transpose ( mx /text->matrix input))))
58
58
(defn parse-lock [input]
59
59
(map (fn [line]
60
60
(dec (count (filter #{\#} line))))
61
- (apply mapv vector ( utils /text->matrix input))))
61
+ (mx/transpose ( mx /text->matrix input))))
62
62
63
63
(defn parse [input]
64
64
(let [lock-or-key (.split input " \n\n " )
Original file line number Diff line number Diff line change
1
+ (ns advent-of-code-clj.matrix )
2
+
3
+ (defn transpose [xs-of-xses]
4
+ (apply mapv vector xs-of-xses))
5
+
6
+ (defn coord-map-fixed
7
+ {:malli/schema [:-> [:sequential [:sequential :any ]] [:map-of [:tuple :int :int ] :any ]]}
8
+ [xs-of-xses]
9
+ (->> xs-of-xses
10
+ (map-indexed (fn [idy xs]
11
+ (map-indexed (fn [idx v]
12
+ [[idy idx] v])
13
+ xs)))
14
+ (transduce cat merge)))
15
+
16
+ (defn text->matrix
17
+ {:malli/schema [:-> :string [:vector [:vector char?]]]}
18
+ [text]
19
+ (mapv vec (.split text " \n " )))
Original file line number Diff line number Diff line change 1
1
(ns advent-of-code-clj.utils
2
- (:import [java.util HashSet]))
2
+ (:import [java.util HashSet])
3
+ (:require
4
+ [advent-of-code-clj.matrix :as mx]))
3
5
4
6
(defn coord-map
5
7
{:malli/schema [:-> [:sequential [:sequential :any ]] [:map-of [:tuple :int :int ] :any ]]}
11
13
xs)))
12
14
(transduce cat merge)))
13
15
14
- (defn coord-map-fixed
15
- {:malli/schema [:-> [:sequential [:sequential :any ]] [:map-of [:tuple :int :int ] :any ]]}
16
- [xs-of-xses]
17
- (->> xs-of-xses
18
- (map-indexed (fn [idy xs]
19
- (map-indexed (fn [idx v]
20
- [[idy idx] v])
21
- xs)))
22
- (transduce cat merge)))
16
+ (def coord-map-fixed mx /coord-map-fixed )
23
17
24
- (defn text->matrix
25
- {:malli/schema [:-> :string [:vector [:vector char?]]]}
26
- [text]
27
- (mapv vec (.split text " \n " )))
18
+ (def text->matrix mx /text->matrix )
28
19
29
20
(defn adjacent-hv
30
21
" Find adjacent coordinates, without diagonals"
You can’t perform that action at this time.
0 commit comments