1
0

Day07 + optimizations

This commit is contained in:
2020-12-07 10:47:14 +01:00
parent b38cdcde07
commit f2280bc2b5
7 changed files with 669 additions and 17 deletions
+7 -9
View File
@@ -11,18 +11,16 @@ class Day06(@Text val input: Input<String>) {
private val groups = input.value.split("\n\n")
fun part1(): Int = groups.map { it.replace("\\s+".toRegex(), "") }
.map { it.toCharArray().toSet() }
.map { it.size }.sum()
fun part1() = groups.sumBy { it.replace("\n", "").toCharArray().toSet().size }
fun part2(): Int = groups.map {
val group = it.split("\n").map { it.trim() }
fun part2() = groups.sumBy {
val group = it.split("\n")
val bag = CharBags.mutable.empty()
group.forEach { chars: String -> chars.forEach { bag.add(it) } }
bag.selectByOccurrences { group.size == it }
.selectUnique()
.size()
}.sum()
bag.selectByOccurrences { group.size == it }.toSet().size()
}
}