1
0
This commit is contained in:
Hubert Van De Walle 2020-12-06 06:21:49 +01:00
parent d394c8697f
commit b38cdcde07
2 changed files with 2231 additions and 0 deletions

View File

@ -0,0 +1,32 @@
package be.vandewalleh.aoc.days
import be.vandewalleh.aoc.utils.input.Day
import be.vandewalleh.aoc.utils.input.Input
import be.vandewalleh.aoc.utils.input.Text
import be.vandewalleh.aoc.utils.input.createDay
import org.eclipse.collections.impl.factory.primitive.CharBags
@Day(6)
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 part2(): Int = groups.map {
val group = it.split("\n").map { it.trim() }
val bag = CharBags.mutable.empty()
group.forEach { chars: String -> chars.forEach { bag.add(it) } }
bag.selectByOccurrences { group.size == it }
.selectUnique()
.size()
}.sum()
}
fun main() = with(createDay<Day06>()) {
println(part1())
println(part2())
}

File diff suppressed because it is too large Load Diff