Day06
This commit is contained in:
parent
d394c8697f
commit
b38cdcde07
32
days/src/main/kotlin/Day06.kt
Normal file
32
days/src/main/kotlin/Day06.kt
Normal 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())
|
||||
}
|
||||
2199
days/src/main/resources/day06.txt
Normal file
2199
days/src/main/resources/day06.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user