Skip to content

Commit d0d8dd6

Browse files
committed
solve 23rd day 1st task
1 parent 67a5941 commit d0d8dd6

File tree

1 file changed

+34
-0
lines changed
  • year2024/src/main/kotlin/net/olegg/aoc/year2024/day23

1 file changed

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

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