Skip to content

Commit 1bb09e5

Browse files
committed
solve 25th day 1st task
1 parent 059ed29 commit 1bb09e5

File tree

1 file changed

+39
-0
lines changed
  • year2024/src/main/kotlin/net/olegg/aoc/year2024/day25

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy