aoc21/d6/p1.go

23 lines
351 B
Go
Raw Normal View History

2022-02-21 22:28:30 +02:00
package d6
import (
"strings"
)
func P1(input string, startDays int) int {
fishes := toNum(strings.Split(strings.TrimSpace(input), ","))
for day := 0; day < startDays; day++ {
for idx := range fishes {
if fishes[idx] == 0 {
fishes[idx] = 6
fishes = append(fishes, 8)
} else {
fishes[idx]--
}
}
}
return len(fishes)
}