Skip to content

Instantly share code, notes, and snippets.

@PhiLhoSoft

PhiLhoSoft/FizzBuzz.ceylon

Last active Aug 29, 2015
Embed
What would you like to do?
Ceylon functional FizzBuzz, two versions
shared void fizzBuzz()
{
print("## FizzBuzz 1 ##");
Iterable<String> fizzBuzz1(Integer count = 20)
{
return (1 .. count).map((Integer c) =>
15.divides(c) then "FizzBuzz" else
(3.divides(c) then "Fizz" else
(5.divides(c) then "Buzz" else c.string)));
}
for (p in fizzBuzz1(50).partition(5)) { print(p); }
print("## FizzBuzz 2 ##");
Iterable<String> fizzBuzz2(Integer count = 20)
{
return (1 .. count).map(
function (Integer c)
{
value f = 3.divides(c);
value b = 5.divides(c);
return
"``f then "Fizz" else ""``
``b then "Buzz" else ""``
``!f && !b then c else ""``"
.replace("\n", ""); // Because I break down the string for readability
});
}
for (p in fizzBuzz2(50).partition(5)) { print(p); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment