diff options
| author | Shawn <shawnw.mobile@gmail.com> | 2020-09-27 22:59:10 -0700 |
|---|---|---|
| committer | Shawn <shawnw.mobile@gmail.com> | 2020-09-28 23:14:03 -0700 |
| commit | 5641718a10d6828f2b22e6c256f8487156cdd0a0 (patch) | |
| tree | 920e31f4cc4e1ecd332160e69b0d53a973b6a256 | |
| parent | 3aee6b4c16f1b4bdfefc5d32f3ee535bf4ed3412 (diff) | |
| download | perlweeklychallenge-club-5641718a10d6828f2b22e6c256f8487156cdd0a0.tar.gz perlweeklychallenge-club-5641718a10d6828f2b22e6c256f8487156cdd0a0.tar.bz2 perlweeklychallenge-club-5641718a10d6828f2b22e6c256f8487156cdd0a0.zip | |
Solutions to challenge 080, both parts, in tcl
| -rwxr-xr-x | challenge-080/shawn-wagner/tcl/ch1.tcl | 20 | ||||
| -rwxr-xr-x | challenge-080/shawn-wagner/tcl/ch2.tcl | 19 |
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-080/shawn-wagner/tcl/ch1.tcl b/challenge-080/shawn-wagner/tcl/ch1.tcl new file mode 100755 index 0000000000..df578d5e42 --- /dev/null +++ b/challenge-080/shawn-wagner/tcl/ch1.tcl @@ -0,0 +1,20 @@ +#!/usr/bin/env tclsh + +# Perl one used hashes, so let's take a different approach in the tcl +# solution; a sorted list. + +proc task1 args { + set N [lsort -integer [lmap n $args { if {$n <= 0} { continue }; set n }]] + set i 1 + set n 0 + set len [llength $N] + while {$n < $len && $i == [lindex $N $n]} { + incr n + incr i + } + puts $i; +} + +task1 5 2 -2 0 +task1 1 8 -1 +task1 2 0 -1 diff --git a/challenge-080/shawn-wagner/tcl/ch2.tcl b/challenge-080/shawn-wagner/tcl/ch2.tcl new file mode 100755 index 0000000000..0f4837d31f --- /dev/null +++ b/challenge-080/shawn-wagner/tcl/ch2.tcl @@ -0,0 +1,19 @@ +#!/usr/bin/env tclsh + +# Same approach as the perl solution + +proc task2 args { + set candies [llength $args] + set len $candies + for {set n 0} {$n < $len} {incr n} { + if {($n > 0 && [lindex $args $n] > [lindex $args $n-1]) || + ($n < $len - 1 && [lindex $args $n] > [lindex $args $n+1])} { + incr candies + } + } + puts $candies +} + + +task2 1 2 2 +task2 1 4 3 2 |
