Skip to content

Commit

Permalink
2023 - Day12 - part 1 - still ugly but refactored a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmmr committed Dec 12, 2023
1 parent 146eb77 commit c33a8c9
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/main/kotlin/no/rodland/advent_2023/Day12.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@ class Day12(val input: List<String>) : Day<Int, Long, List<Pair<List<String>, Li
private val parsed = input.parse()

override fun partOne(): Int {
val hei = parsed.map { (candidates, ints) ->
val map = candidates.map {
it.split("\\.+".toRegex()).filterNot { it.isEmpty() }
}
val sameSize = map.filter { it.size == ints.size }
val lengths = sameSize.map { strings ->
strings.map { it.length }
}
val matches = lengths.count {
it == ints
}
matches
val hei = parsed.map { (candidates, numbers) ->
candidates
.map { candidate -> candidate.split("\\.+".toRegex()).filterNot { it.isEmpty() } }
.filter { it.size == numbers.size }
.map { strings -> strings.map { it.length } }
.count { it == numbers }
}
return hei.sum()
}
Expand Down

0 comments on commit c33a8c9

Please sign in to comment.