From 8d0f6e0eb5075b8f0fc726a16b712b9d262df073 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 6 Jan 2022 20:36:50 +0100 Subject: Week 3, part 2: Tcl solution --- challenge-003/abigail/README.md | 1 + challenge-003/abigail/tcl/ch-2.tcl | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 challenge-003/abigail/tcl/ch-2.tcl 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] + } +} -- cgit