aboutsummaryrefslogtreecommitdiff
path: root/challenge-003
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.freedom.nl>2022-01-06 20:36:50 +0100
committerAbigail <abigail@abigail.freedom.nl>2022-01-06 20:36:50 +0100
commit8d0f6e0eb5075b8f0fc726a16b712b9d262df073 (patch)
tree586459b4e533a3e4945534ccbece1067573bc65a /challenge-003
parent5ad1d875e914f3a6f67d04e2f46652180b463a5e (diff)
downloadperlweeklychallenge-club-8d0f6e0eb5075b8f0fc726a16b712b9d262df073.tar.gz
perlweeklychallenge-club-8d0f6e0eb5075b8f0fc726a16b712b9d262df073.tar.bz2
perlweeklychallenge-club-8d0f6e0eb5075b8f0fc726a16b712b9d262df073.zip
Week 3, part 2: Tcl solution
Diffstat (limited to 'challenge-003')
-rw-r--r--challenge-003/abigail/README.md1
-rw-r--r--challenge-003/abigail/tcl/ch-2.tcl27
2 files changed, 28 insertions, 0 deletions
diff --git a/challenge-003/abigail/README.md b/challenge-003/abigail/README.md
index 457b8caa5a..6adf435e09 100644
--- a/challenge-003/abigail/README.md
+++ b/challenge-003/abigail/README.md
@@ -32,3 +32,4 @@
* [Python](python/ch-2.py)
* [R](r/ch-2.r)
* [Ruby](ruby/ch-2.rb)
+* [Tcl](tcl/ch-2.tcl)
diff --git a/challenge-003/abigail/tcl/ch-2.tcl b/challenge-003/abigail/tcl/ch-2.tcl
new file mode 100644
index 0000000000..ac8f8ef600
--- /dev/null
+++ b/challenge-003/abigail/tcl/ch-2.tcl
@@ -0,0 +1,27 @@
+#!/usr/local/opt/tcl-tk/bin/tclsh
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003
+#
+
+#
+# Run as: tclsh ch-2.tcl < input-file
+#
+
+while {[gets stdin max] >= 0} {
+ set current_row(0) 1
+ puts 1
+ for {set row 1} {$row <= $max} {incr row} {
+ set next_row(0) 1
+ set next_row($row) 1
+ puts -nonewline "1 "
+ for {set col 1} {$col < $row} {incr col} {
+ set next_row($col) \
+ [expr $current_row([expr $col - 1]) + $current_row($col)]
+ puts -nonewline $next_row($col)
+ puts -nonewline " "
+ }
+ puts 1
+ array set current_row [array get next_row]
+ }
+}