-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day06.kt
45 lines (33 loc) · 914 Bytes
/
Day06.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package y2021
import general.Day
object Day06 : Day() {
override val name = "Lanternfish"
override fun a1() {
val input = INPUT.readText().split(",").map { it.toInt() }
val list = IntArray(9)
for (fish in input)
list[fish] += 1
repeat (80) {
val zero = list[0]
for (day in 1..8)
list[day - 1] = list[day]
list[8] = zero
list[6] += zero
}
println(list.sum())
}
override fun a2() {
val input = INPUT.readText().split(",").map { it.toInt() }
val list = LongArray(9)
for (fish in input)
list[fish] += 1L
repeat (256) {
val zero = list[0]
for (day in 1..8)
list[day - 1] = list[day]
list[8] = zero
list[6] += zero
}
println(list.sum())
}
}