RosettaCodeData/Task/FizzBuzz/Pyret/fizzbuzz.arr

19 lines
623 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
fun fizzbuzz(n :: NumPositive) -> String:
doc: ```For positive input which is multiples of three return 'Fizz', for the multiples of five return 'Buzz'.
For numbers which are multiples of both three and five return 'FizzBuzz'. Otherwise, return the number itself.```
ask:
| num-modulo(n, 15) == 0 then: "FizzBuzz"
| num-modulo(n, 3) == 0 then: "Fizz"
| num-modulo(n, 5) == 0 then: "Buzz"
| otherwise: num-to-string(n)
end
where:
fizzbuzz(1) is "1"
fizzbuzz(101) is "101"
fizzbuzz(45) is "FizzBuzz"
fizzbuzz(33) is "Fizz"
fizzbuzz(25) is "Buzz"
end
range(1, 101).map(fizzbuzz).each(print)