Posted to tcl by dbohdan at Sat May 09 18:44:24 GMT 2015view pretty
set num {1 2 3 4 5 6 7 8 9} set correct {} for { set i 0 } { $i < 3 ** ([llength $num] - 1) } { incr i } { set n $i set s {} set t $num while { [llength $t] > 0 } { append s [lindex $t 0] set t [lrange $t 1 end] switch -exact -- [expr { $n % 3 }] { 0 {} 1 { append s - } 2 { append s + } } set n [expr { $n / 3 }] } if { [expr $s] == 100 } { lappend correct $s } } puts [llength $correct]\n\t[join $correct \n\t]