We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b0bb9d6 commit f1f3f4cCopy full SHA for f1f3f4c
archive/t/tcl/fizz-buzz.tcl
@@ -0,0 +1,25 @@
1
+# This approach is exclusively to show the capabilities and flexibility of Tcl.
2
+# It doesn't deserve being this overengineered in the normal case. :P
3
+
4
+proc fizzbuzz {rules {limit 100}} {
5
+ namespace eval ::fizzbuzz {
6
+ namespace export *
7
+ namespace ensemble create
8
+ }
9
10
+ foreach {div word} $rules {
11
+ proc ::fizzbuzz::$word {n} [format {
12
+ expr {($n %% %d) == 0 ? "%s" : ""}
13
+ } $div $word]
14
15
16
+ for {set n 1} {$n <= $limit} {incr n} {
17
+ set s ""
18
19
+ append s [::fizzbuzz::$word $n]
20
21
+ puts [expr {$s eq "" ? $n : $s}]
22
23
+}
24
25
+fizzbuzz {3 Fizz 5 Buzz}
0 commit comments