advent-of-code-2021/6/part1.go
2021-12-18 16:28:02 +01:00

33 lines
467 B
Go

package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
var fishes []int
s := bufio.NewScanner(os.Stdin)
s.Scan()
for _, fishStr := range strings.Split(s.Text(), ",") {
fish, _ := strconv.Atoi(fishStr)
fishes = append(fishes, fish)
}
for x := 0; x < 80; x++ {
for i := range fishes {
if fishes[i] == 0 {
fishes[i] = 6
fishes = append(fishes, 8)
} else {
fishes[i]--
}
}
}
fmt.Println(len(fishes))
}