Skip to content

Commit 4b525e8

Browse files
committed
part 2 but much toooooooooooooooooooooooooo slow...
1 parent 131c509 commit 4b525e8

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
// project meta data
66
group 'de.havox_design.aoc2023'
7-
version '0.11.3'
7+
version '0.11.4'
88

99
// Switch to gradle "all" distribution.
1010
wrapper {

day12/src/main/kotlin/de/havox_design/aoc2023/day12/Day12.kt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,32 @@ class Day12(private var filename: String) {
1414
}
1515

1616
fun solvePart2(): Long =
17-
525152L
17+
getResourceAsText(filename)
18+
.map { parseInput(it, true) }
19+
.sumOf {
20+
it
21+
.possibleGroups
22+
.count()
23+
}
1824

19-
private fun parseInput(row: String): Record {
25+
private fun parseInput(row: String, folded: Boolean = false): Record {
2026
val (text, groups) = row
2127
.split(DATA_DELIMITER)
28+
val groupDistribution = groups
29+
.split(GROUPS_DELIMITER)
30+
.map { it.toInt() }
31+
32+
return when {
33+
folded -> {
34+
Record(
35+
"$text?$text?$text?$text?$text",
36+
listOf(groupDistribution, groupDistribution, groupDistribution, groupDistribution, groupDistribution)
37+
.flatten()
38+
)
39+
}
2240

23-
return Record(
24-
text,
25-
groups
26-
.split(GROUPS_DELIMITER)
27-
.map { it.toInt() }
28-
)
41+
else -> Record(text, groupDistribution)
42+
}
2943
}
3044

3145
private fun getResourceAsText(path: String): List<String> =

0 commit comments

Comments
 (0)