blob: 68f16ef27a07e4db344da2c47c274e9b92cf663b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
|