diff options
| -rwxr-xr-x | challenge-086/shawn-wagner/tcl/ch-1.tcl | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-086/shawn-wagner/tcl/ch-1.tcl b/challenge-086/shawn-wagner/tcl/ch-1.tcl new file mode 100755 index 0000000000..43c6ab5ea1 --- /dev/null +++ b/challenge-086/shawn-wagner/tcl/ch-1.tcl @@ -0,0 +1,30 @@ +#!/usr/bin/env tclsh +package require generator ;# From tcllib + +generator define genpairs {list} { + for {set m 0} {$m < [llength $list]} {incr m} { + for {set n 0} {$n < [llength $list]} {incr n} { + if {$m != $n} { + generator yield [::list [lindex $list $m] [lindex $list $n]] + } + } + } +} + +proc diffne {total pair} { + lassign $pair a b + expr {$a - $b != $total} +} + +proc task1 {N A} { + generator foreach match [generator dropWhile [list diffne $A] [genpairs $N]] { + lassign $match a b + puts "1 as $a - $b = $A" + return + } + puts 0 +} + +task1 {10 8 12 15 5} 7 +task1 {1 5 2 9 7} 6 +task1 {10 30 20 50 40} 15 |
