From f1e2dc0d24d87de8d27885351ae8b6bc83730579 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Wed, 6 Dec 2023 07:06:20 +0000 Subject: [PATCH] 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. --- day06/sol.tcl | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/day06/sol.tcl b/day06/sol.tcl index 6614701..6ab9412 100755 --- a/day06/sol.tcl +++ b/day06/sol.tcl @@ -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]]"