diff options
| author | Shawn Wagner <shawnw.mobile@gmail.com> | 2020-11-14 23:28:11 -0800 |
|---|---|---|
| committer | Shawn Wagner <shawnw.mobile@gmail.com> | 2020-11-14 23:28:41 -0800 |
| commit | 434f0f0dd0259e347fa5b930c557d69404dc491b (patch) | |
| tree | 0331b2df2cb6db266cef94829678c84c488dbff3 | |
| parent | 0fb63a08b1a38243ba113aeb760f6130376cd069 (diff) | |
| download | perlweeklychallenge-club-434f0f0dd0259e347fa5b930c557d69404dc491b.tar.gz perlweeklychallenge-club-434f0f0dd0259e347fa5b930c557d69404dc491b.tar.bz2 perlweeklychallenge-club-434f0f0dd0259e347fa5b930c557d69404dc491b.zip | |
Challenge 086, part 1 solution in tcl
| -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 |
