#!/usr/bin/env tclsh8.6 gets stdin line set fish [split $line ,] for {set i 0} {$i <= 8} {incr i} {set count($i) 0} foreach f $fish { incr count($f) } for {set day 1} {$day <= 256} {incr day} { set spawn $count(0) for {set i 0} {$i < 8} {incr i} { set count($i) $count([expr {$i+1}]) } incr count(6) $spawn set count(8) $spawn } set n 0 foreach {key val} [array get count] {incr n $val} puts $n