diff options
| author | Shawn <shawnw.mobile@gmail.com> | 2020-08-09 23:49:03 -0700 |
|---|---|---|
| committer | Shawn <shawnw.mobile@gmail.com> | 2020-08-09 23:49:03 -0700 |
| commit | 80ae88a108608ff7087b5b2893c0ed998f73086f (patch) | |
| tree | ff777f41ea427da4c51ea18eded1880707289712 /challenge-073 | |
| parent | 7002e2441ff0a8700abb7d8fd1bbcf0108dbe14c (diff) | |
| download | perlweeklychallenge-club-80ae88a108608ff7087b5b2893c0ed998f73086f.tar.gz perlweeklychallenge-club-80ae88a108608ff7087b5b2893c0ed998f73086f.tar.bz2 perlweeklychallenge-club-80ae88a108608ff7087b5b2893c0ed998f73086f.zip | |
Challenge 073 solutions in tcl
Diffstat (limited to 'challenge-073')
| -rwxr-xr-x | challenge-073/shawn-wagner/tcl/ch-1.tcl | 14 | ||||
| -rwxr-xr-x | challenge-073/shawn-wagner/tcl/ch-2.tcl | 20 |
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-073/shawn-wagner/tcl/ch-1.tcl b/challenge-073/shawn-wagner/tcl/ch-1.tcl new file mode 100755 index 0000000000..79bf8f60cf --- /dev/null +++ b/challenge-073/shawn-wagner/tcl/ch-1.tcl @@ -0,0 +1,14 @@ +#!/usr/bin/env tclsh +package require Tcl 8.6 + +proc task1 {A S} { + incr S -1 + set last_index [expr {[llength $A] - $S}] + for {set i 0} {$i < $last_index} {incr i} { + lappend results [::tcl::mathfunc::min {*}[lrange $A $i $i+$S]] + } + puts "Task 1:\t$results" +} + +task1 {1 5 0 2 9 3 7 6 4 8} 3 + diff --git a/challenge-073/shawn-wagner/tcl/ch-2.tcl b/challenge-073/shawn-wagner/tcl/ch-2.tcl new file mode 100755 index 0000000000..3f6f8d7daf --- /dev/null +++ b/challenge-073/shawn-wagner/tcl/ch-2.tcl @@ -0,0 +1,20 @@ +#!/usr/bin/env tclsh +package require Tcl 8.6 + +proc task2 {A} { + set last_index [llength $A] + set results [list 0] + for {set i 1} {$i < $last_index} {incr i} { + set m [::tcl::mathfunc::min {*}[lrange $A 0 $i-1]] + if {$m < [lindex $A $i]} { + lappend results $m + } else { + lappend results 0 + } + } + puts "Task 2:\t$results" +} + +task2 {7 8 3 12 10} +task2 {4 6 5} + |
