adventofcode2023/day02/sol.tcl

24 lines
613 B
Tcl
Executable File

#!/usr/bin/env tclsh
source ../prelude.tcl
set input stdin
set total 0
set power 0
while {[gets $input line] >= 0} {
regexp {Game (\d+): (.*)} $line _ num takes
set min(red) 0
set min(blue) 0
set min(green) 0
foreach t [split $takes ";"] {
foreach {n color} [string map {, {}} $t] {
set min($color) [max $min($color) $n]
}
}
if {$min(red) <= 12 && $min(blue) <= 14 && $min(green) <= 13} {
incr total $num
}
incr power [expr {$min(red) * $min(blue) * $min(green)}]
#puts "${min(red)} ${min(blue)} ${min(green)}"
}
puts $total
puts $power