generated from Jadarma/advent-of-code-kotlin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathY2016D06.kt
22 lines (18 loc) · 873 Bytes
/
Y2016D06.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package aockt.y2016
import io.github.jadarma.aockt.core.Solution
object Y2016D06 : Solution {
private fun Sequence<String>.filterNoise(selector: Iterable<Map.Entry<Char, Int>>.() -> Map.Entry<Char, Int>) =
List(first().length) { mutableMapOf<Char, Int>() }
.apply {
[email protected] { line ->
line.forEachIndexed { index, char ->
val current = get(index).getOrDefault(char, 0)
get(index)[char] = current + 1
}
}
}
.map { it.entries.selector().key }
.joinToString("")
override fun partOne(input: String) = input.lineSequence().filterNoise { maxByOrNull { it.value }!! }
override fun partTwo(input: String) = input.lineSequence().filterNoise { minByOrNull { it.value }!! }
}