package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func main() { // https://en.wiktionary.org/wiki/fishes#English fishes := map[int]int{} s := bufio.NewScanner(os.Stdin) s.Scan() for _, fishStr := range strings.Split(s.Text(), ",") { fish, _ := strconv.Atoi(fishStr) fishes[fish]++ } for x := 0; x < 256; x++ { newFishes := map[int]int{} // handle usual decrements for i := 8; i > 0; i-- { newFishes[i-1] = fishes[i] } // handle the new fishes newFishes[6] += fishes[0] newFishes[8] += fishes[0] fishes = newFishes } sum := 0 for _, count := range fishes { sum += count } fmt.Println(sum) }