#!/usr/bin/env tclsh8.6 set total 0 while {[gets stdin line] >= 0} { set line [string map {{ } {}} $line] set line [lindex [split $line :] 1] set red 1; set green 1; set blue 1 foreach group [split $line \;] { foreach marbles [split $group ,] { scan $marbles %d%s number color switch -- $color { red {if {$number > $red} {set red $number}} green {if {$number > $green} {set green $number}} blue {if {$number > $blue} {set blue $number}} } } } set power [expr {$red * $green * $blue}] incr total $power } puts $total