advent-of-code-2021/6/part1.go

34 lines
467 B
Go
Raw Normal View History

2021-12-06 06:41:51 +00:00
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))
}