aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2024-04-28 08:03:52 +0100
committerJuan J. Martinez <jjm@usebox.net>2024-04-28 08:03:52 +0100
commit6bab39bc31624edbc3dd974e6fab94810d71d1a7 (patch)
tree06aa58b749208ddccfb02e8a3d0a6ab361d40d93 /examples
parentf3401bb71f8d771e0b9cf099fa1f497afa58b8b2 (diff)
downloadfunco-6bab39bc31624edbc3dd974e6fab94810d71d1a7.tar.gz
funco-6bab39bc31624edbc3dd974e6fab94810d71d1a7.zip
FizzBuzz solution
Diffstat (limited to 'examples')
-rw-r--r--examples/fizzbuzz.fco31
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/fizzbuzz.fco b/examples/fizzbuzz.fco
new file mode 100644
index 0000000..68f16ef
--- /dev/null
+++ b/examples/fizzbuzz.fco
@@ -0,0 +1,31 @@
+# returns Fizz if n is divisible by 3,
+# Buzz if n is divisible by 5,
+# FizzBuzz if n is divisible by 3 and 5,
+# n as a string otherwise
+def fizzbuzz(n)
+ if =(+(mod(n 3) mod(n 5)) 0)
+ "FizzBuzz"
+ elif =(mod(n 3) 0)
+ "Fizz"
+ elif =(mod(n 5) 0)
+ "Buzz"
+ else
+ string(n)
+ end
+end
+
+# generate a list of integers from n to top
+def genlist(n top)
+ def rec(l n top)
+ if <=(n top)
+ @rec(+(l list(n)) +(n 1) top)
+ else
+ l
+ end
+ end
+ rec(list() n top)
+end
+
+def main()
+ display(map(fizzbuzz genlist(1 20)))
+end