aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-02-23 08:15:41 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-02-23 08:15:41 +0000
commiteb39ddda8ac5d602e552fab5289191be7e1bcf5b (patch)
tree6b6c4026ecfe8c9eaceb0dea2736ea053749ff82
parente1cebcb299a7ddafcaa9d19c4cd1ac39d108a708 (diff)
downloadperlweeklychallenge-club-eb39ddda8ac5d602e552fab5289191be7e1bcf5b.tar.gz
perlweeklychallenge-club-eb39ddda8ac5d602e552fab5289191be7e1bcf5b.tar.bz2
perlweeklychallenge-club-eb39ddda8ac5d602e552fab5289191be7e1bcf5b.zip
- Added more guest contribution by Robert DiCicco.
-rw-r--r--challenge-153/robert-dicicco/tcl/ch-2.tcl33
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-153/robert-dicicco/tcl/ch-2.tcl b/challenge-153/robert-dicicco/tcl/ch-2.tcl
new file mode 100644
index 0000000000..2f7b2a9437
--- /dev/null
+++ b/challenge-153/robert-dicicco/tcl/ch-2.tcl
@@ -0,0 +1,33 @@
+# Author: Robert DiCicco
+# Date: 22-FEB-2022
+# Challenge # 153 Factorions (Tcl)
+
+proc Factorial {x} {
+ set i 1; set product 1
+ while {$i <= $x } {
+ set product [expr $product * $i]
+ incr i
+ }
+
+ return $product
+}
+
+set i [lindex $argv 0 ]
+set digits [split $i {}]
+set finalsum 0
+
+puts "Input: $i"
+
+foreach num $digits {
+ set X [Factorial $num]
+ puts -nonewline "$num! + "
+ set finalsum [ expr $finalsum + $X ]
+}
+
+puts "\b\b\b = $finalsum"
+
+if {$i == $finalsum} {
+ puts "Output: 1"
+} else {
+ puts "Output: 0"
+}