slightly more idiomatic tcl?

lmul is a more idiomatic name than product.
using join+eval is probably slower than foreach but the lists are small
so i don't care.
main
magical 2023-12-06 07:06:20 +00:00
parent 905dee030f
commit f1e2dc0d24
1 changed files with 3 additions and 10 deletions

View File

@ -29,15 +29,8 @@ proc solve {t d} {
return [expr {$b - $a}] return [expr {$b - $a}]
} }
proc product {list} { proc lmul {list} { return [expr [join $list *]] }
set p 1 proc smush {list} { return [join $list ""] }
foreach x $list {
set p [expr {$p * $x}]
}
return $p
}
proc smush {x} { return [join $x ""] } puts "Part 1: [lmul [lmap t $time d $dist {solve $t $d}]]"
puts "Part 1: [product [lmap t $time d $dist {solve $t $d}]]"
puts "Part 2: [solve [smush $time] [smush $dist]]" puts "Part 2: [solve [smush $time] [smush $dist]]"