File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
year2024/src/main/kotlin/net/olegg/aoc/year2024/day25 Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ package net.olegg.aoc.year2024.day25
2
+
3
+ import net.olegg.aoc.someday.SomeDay
4
+ import net.olegg.aoc.utils.transpose
5
+ import net.olegg.aoc.year2024.DayOf2024
6
+
7
+ /* *
8
+ * See [Year 2024, Day 25](https://adventofcode.com/2024/day/25)
9
+ */
10
+ object Day25 : DayOf2024(25 ) {
11
+ override fun first (): Any? {
12
+ val rawSets = data.split(" \n\n " )
13
+ val (rawLocks, rawKeys) = rawSets.partition { it.startsWith(" #" ) }
14
+
15
+ val locks = rawLocks.map { rawLock ->
16
+ rawLock.lines()
17
+ .map { it.toList() }
18
+ .transpose()
19
+ .map { column -> column.count { it == ' #' } }
20
+ }
21
+
22
+ val keys = rawKeys.map { rawKey ->
23
+ rawKey.lines()
24
+ .map { it.toList() }
25
+ .transpose()
26
+ .map { column -> column.count { it == ' #' } }
27
+ }
28
+
29
+ val size = rawLocks.first().lines().count()
30
+
31
+ return locks.sumOf { lock ->
32
+ keys.count { key ->
33
+ lock.zip(key).all { it.first + it.second <= size }
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ fun main () = SomeDay .mainify(Day25 )
You can’t perform that action at this time.
0 commit comments