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
parent
905dee030f
commit
f1e2dc0d24
|
@ -29,15 +29,8 @@ proc solve {t d} {
|
|||
return [expr {$b - $a}]
|
||||
}
|
||||
|
||||
proc product {list} {
|
||||
set p 1
|
||||
foreach x $list {
|
||||
set p [expr {$p * $x}]
|
||||
}
|
||||
return $p
|
||||
}
|
||||
proc lmul {list} { return [expr [join $list *]] }
|
||||
proc smush {list} { return [join $list ""] }
|
||||
|
||||
proc smush {x} { return [join $x ""] }
|
||||
|
||||
puts "Part 1: [product [lmap t $time d $dist {solve $t $d}]]"
|
||||
puts "Part 1: [lmul [lmap t $time d $dist {solve $t $d}]]"
|
||||
puts "Part 2: [solve [smush $time] [smush $dist]]"
|
||||
|
|
Loading…
Reference in New Issue