B:BD[
2.308] → [
2.308:739]
fun solve(input: List<Int>, days: Int): BigInteger {
var fish = input
.groupingBy { it }
.eachCount()
.mapValues { it.value.toBigInteger() }
.toMutableMap()
for (day in 1..days) {
fish = fish.mapKeys { (9 + it.key.minus(1)) % 9 }.toMutableMap()
fish[6] = (fish[6] ?: 0.toBigInteger()).add(fish[8] ?: 0.toBigInteger())
}
return fish.values.reduce { a, b -> a.add(b) }
fun solve(input: Map<Int, Int>, days: Int): BigInteger {
val fish = Array(9) { (input[it] ?: 0).toBigInteger() }
(1 until days).forEach { fish[(it + 7) % 9] += fish[it % 9] }
return fish.reduce { a, b -> a + b }