day(08): reformat
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
6bfe301f7b
commit
a06cc306b8
1 changed files with 12 additions and 3 deletions
|
@ -75,14 +75,23 @@ fun part1(input: List<String>): Int = input.sumOf { entry ->
|
||||||
val (patterns, output) = entry.split(" | ")
|
val (patterns, output) = entry.split(" | ")
|
||||||
val decodedPatterns = Patterns(patterns).decode()
|
val decodedPatterns = Patterns(patterns).decode()
|
||||||
|
|
||||||
output.split(" ").map { it.toSet() }.count { decodedPatterns.values.contains(it) }
|
output
|
||||||
|
.split(" ")
|
||||||
|
.count { decodedPatterns.values.contains(it.toSet()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun part2(input: List<String>): Int = input.sumOf { entry ->
|
fun part2(input: List<String>): Int = input.sumOf { entry ->
|
||||||
val (patterns, output) = entry.split(" | ")
|
val (patterns, output) = entry.split(" | ")
|
||||||
val decodedPatterns = Patterns(patterns).decode(true).map { (key, value) -> Pair(value, key) }.toMap()
|
val decodedPatterns = Patterns(patterns)
|
||||||
|
.decode(true)
|
||||||
|
.map { (key, value) -> Pair(value, key) }
|
||||||
|
.toMap()
|
||||||
|
|
||||||
output.split(" ").map { it.toSet() }.fold(0) { n, digit -> 10 * n + decodedPatterns[digit]!! }.toLong()
|
output
|
||||||
|
.split(" ")
|
||||||
|
.map { it.toSet() }
|
||||||
|
.fold(0) { n, digit -> 10 * n + decodedPatterns[digit]!! }
|
||||||
|
.toLong()
|
||||||
}.toInt()
|
}.toInt()
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
|
|
Loading…
Reference in a new issue