aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-10-19 20:02:55 +0200
committerAbigail <abigail@abigail.be>2021-10-19 20:02:55 +0200
commitec0548d9d1f8f277a0cd78d5a626c4efdd42f3ef (patch)
tree45a24d4f75371a676e782f445687ef3a7582b4b3
parent5f51c70957a90c3ea098217e195c8f84dd87d389 (diff)
downloadperlweeklychallenge-club-ec0548d9d1f8f277a0cd78d5a626c4efdd42f3ef.tar.gz
perlweeklychallenge-club-ec0548d9d1f8f277a0cd78d5a626c4efdd42f3ef.tar.bz2
perlweeklychallenge-club-ec0548d9d1f8f277a0cd78d5a626c4efdd42f3ef.zip
Tcl solutions for week 135
-rw-r--r--challenge-135/abigail/README.md2
-rw-r--r--challenge-135/abigail/tcl/ch-1.tcl23
-rw-r--r--challenge-135/abigail/tcl/ch-2.tcl31
3 files changed, 56 insertions, 0 deletions
diff --git a/challenge-135/abigail/README.md b/challenge-135/abigail/README.md
index ef6c3b18c8..b0164d2fd2 100644
--- a/challenge-135/abigail/README.md
+++ b/challenge-135/abigail/README.md
@@ -10,6 +10,7 @@
* [Perl](perl/ch-1.pl)
* [Python](python/ch-1.py)
* [Ruby](ruby/ch-1.rb)
+* [Tcl](tcl/ch-1.tcl)
## Part 2
@@ -21,3 +22,4 @@
* [Perl](perl/ch-2.pl)
* [Python](python/ch-2.py)
* [Ruby](ruby/ch-2.rb)
+* [Tcl](tcl/ch-2.tcl)
diff --git a/challenge-135/abigail/tcl/ch-1.tcl b/challenge-135/abigail/tcl/ch-1.tcl
new file mode 100644
index 0000000000..b4024a86a5
--- /dev/null
+++ b/challenge-135/abigail/tcl/ch-1.tcl
@@ -0,0 +1,23 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: tclsh ch-1.tcl < input-file
+#
+
+while {[gets stdin line] >= 0} {
+ if {[regexp {^[-+]?([0-9]+)$} $line -> digits]} {
+ set ll [string length $digits]
+ if {[expr $ll % 2] == 0} {
+ puts "even number of digits"
+ } elseif {[expr $ll < 3]} {
+ puts "too short"
+ } else {
+ puts [string range $digits [expr ($ll - 3) / 2]\
+ [expr ($ll + 2) / 2]]
+ }
+ } else {
+ puts "not an integer"
+ }
+}
diff --git a/challenge-135/abigail/tcl/ch-2.tcl b/challenge-135/abigail/tcl/ch-2.tcl
new file mode 100644
index 0000000000..9df349e33b
--- /dev/null
+++ b/challenge-135/abigail/tcl/ch-2.tcl
@@ -0,0 +1,31 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: tclsh ch-2.tcl < input-file
+#
+
+set w {1 3 1 7 3 9 1}
+
+while {[gets stdin line] >= 0} {
+ if {[regexp {^[0-9BCDFGHJKLMNPQRSTVWXYZ]{7}$} $line]} {
+ set check 0
+ for {set i 0} {$i < [string length $line]} {incr i} {
+ set val [scan [string index $line $i] %c]
+ if {[expr $val <= [scan "9" %c]]} {
+ set val [expr $val - [scan "0" %c]]
+ } else {
+ set val [expr $val - [scan "A" %c] + 10]
+ }
+ set check [expr $check + [lindex $w $i] * $val]
+ }
+ if {[expr $check % 10] == 0} {
+ puts 1
+ } else {
+ puts 0
+ }
+ } else {
+ puts 0
+ }
+}