Compare commits

..

No commits in common. "f58ed8eb9792dbf8d75b4b5b450a92342089a2ae" and "f1e2dc0d24d87de8d27885351ae8b6bc83730579" have entirely different histories.

3 changed files with 0 additions and 67 deletions

View File

@ -1,23 +0,0 @@
#!/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

View File

@ -1,28 +0,0 @@
#!/usr/bin/env tclsh
source ../prelude.tcl
package require struct::set
set input stdin
set part1 0
while {[gets $input line] >= 0} {
regexp {^Card +(\d+): ([\d ]*) \| ([\d ]*)$} $line _ card winners numbers
set matches [struct::set intersect $winners $numbers]
set score [expr {1 << [llength $matches] >> 1}]
incr part1 $score
incr copies($card)
for {set i 0} {$i < [llength $matches]} {incr i} {
incr copies([expr {$card+$i+1}]) $copies($card)
}
}
puts "-"
puts $part1
foreach {c n} [array get copies] {
if {$c > $card} {
error "should not have any copies of card $c > $card"
}
}
set part2 [ladd [lmap {card n} [array get copies] {list $n}]]
puts $part2

View File

@ -1,16 +0,0 @@
package require Tcl 8.6
namespace import tcl::mathfunc::min
namespace import tcl::mathfunc::max
proc ladd {list} {
set t 0
foreach x $list { incr t $x }
return $t
}
proc lmul {list} {
set p 1
foreach x $list { set p [eval {$p * $x}] }
return $p
}