diff options
| author | Abigail <abigail@abigail.freedom.nl> | 2021-12-27 18:20:34 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.freedom.nl> | 2021-12-29 20:19:41 +0100 |
| commit | a7cfe19e7988033b8b37d4effedcf01ee203ff0e (patch) | |
| tree | ab78dd124aef81b9f58ec35ca24e9b768e1d3512 /challenge-145/abigail/tcl | |
| parent | 767f501835ea07823607293b532b6a0520fafc3b (diff) | |
| download | perlweeklychallenge-club-a7cfe19e7988033b8b37d4effedcf01ee203ff0e.tar.gz perlweeklychallenge-club-a7cfe19e7988033b8b37d4effedcf01ee203ff0e.tar.bz2 perlweeklychallenge-club-a7cfe19e7988033b8b37d4effedcf01ee203ff0e.zip | |
Week 145
Diffstat (limited to 'challenge-145/abigail/tcl')
| -rw-r--r-- | challenge-145/abigail/tcl/ch-1.tcl | 17 | ||||
| -rw-r--r-- | challenge-145/abigail/tcl/ch-2.tcl | 20 |
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-145/abigail/tcl/ch-1.tcl b/challenge-145/abigail/tcl/ch-1.tcl new file mode 100644 index 0000000000..46a9abcdba --- /dev/null +++ b/challenge-145/abigail/tcl/ch-1.tcl @@ -0,0 +1,17 @@ +# +# See ../README.md +# + +# +# Run as: tclsh ch-1.tcl < input-file +# + +set a [split [gets stdin] " "] +set b [split [gets stdin] " "] + +set sum 0 +for {set i 0} {$i < [llength $a]} {incr i} { + set sum [expr $sum + [lindex $a $i] * [lindex $b $i]] +} + +puts $sum diff --git a/challenge-145/abigail/tcl/ch-2.tcl b/challenge-145/abigail/tcl/ch-2.tcl new file mode 100644 index 0000000000..13645cea5b --- /dev/null +++ b/challenge-145/abigail/tcl/ch-2.tcl @@ -0,0 +1,20 @@ +# +# See ../README.md +# + +# +# Run as: tclsh ch-2.tcl < input-file +# + +while {[gets stdin line] >= 0} { + set palindromes [dict create] + for {set i 0} {$i < [string length $line]} {incr i} { + for {set j $i} {$j < [string length $line]} {incr j} { + set str [string range $line $i $j] + if {$str == [string reverse $str]} { + dict set palindromes $str 1 + } + } + } + puts [dict keys $palindromes] +} |
