#!/usr/bin/env tclsh8.6 set total 0 set maxred 12; set maxgreen 13; set maxblue 14 set re {\d+ (?:blue|red|green)} while {[gets stdin line] >= 0} { scan $line {Game %d:} game set ok 1 foreach marbles [regexp -all -inline $re $line] { lassign $marbles number color switch -- $color { red {if {$number > $maxred} {set ok 0}} green {if {$number > $maxgreen} {set ok 0}} blue {if {$number > $maxblue} {set ok 0}} } } if {$ok} {incr total $game} } puts $total