File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
year2024/src/main/kotlin/net/olegg/aoc/year2024/day23 Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ package net.olegg.aoc.year2024.day23
2
+
3
+ import net.olegg.aoc.someday.SomeDay
4
+ import net.olegg.aoc.utils.parseInts
5
+ import net.olegg.aoc.utils.toPair
6
+ import net.olegg.aoc.utils.transpose
7
+ import net.olegg.aoc.year2024.DayOf2024
8
+ import kotlin.math.absoluteValue
9
+
10
+ /* *
11
+ * See [Year 2024, Day 23](https://adventofcode.com/2024/day/23)
12
+ */
13
+ object Day23 : DayOf2024(23 ) {
14
+ override fun first (): Any? {
15
+ val connections = lines.map { it.split(" -" ).sorted() }
16
+
17
+ return connections.flatMapIndexed { i, connI ->
18
+ connections.drop(i + 1 ).flatMapIndexed { j, connJ ->
19
+ val subset = (connI + connJ).toSet()
20
+ if (subset.size == 3 ) {
21
+ connections.drop(i + 1 + j + 1 ).mapNotNull { connK ->
22
+ (subset + connK).toSet().takeIf { it.size == 3 }
23
+ }
24
+ } else {
25
+ emptyList()
26
+ }
27
+ }
28
+ }.count { set ->
29
+ set.any { it.startsWith(" t" ) }
30
+ }
31
+ }
32
+ }
33
+
34
+ fun main () = SomeDay .mainify(Day23 )
You can’t perform that action at this time.
0 commit comments