Skip to content

Instantly share code, notes, and snippets.

@PhiLhoSoft
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PhiLhoSoft/8f78fd06f8306a4e0578 to your computer and use it in GitHub Desktop.
Save PhiLhoSoft/8f78fd06f8306a4e0578 to your computer and use it in GitHub Desktop.
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