Skip to content

Instantly share code, notes, and snippets.

@repeatedly
Created August 9, 2012 07:41
Show Gist options
  • Save repeatedly/3302048 to your computer and use it in GitHub Desktop.
Save repeatedly/3302048 to your computer and use it in GitHub Desktop.
FizzBuzz based on tanakh's Haskell
import std.algorithm, std.conv, std.range, std.stdio;
// FizzBuzz from http://ideone.com/ciKtm
// I cannot port 'f <> b <|> n'
void main()
{
auto fizz = cycle([null, null, "Fizz"]);
auto buzz = cycle([null, null, null, null, "Buzz"]);
auto nums = map!(to!string)(iota(1, 101));
foreach (num; map!(e => (e[0] ~ e[1]).empty ? e[2] : e[0] ~ e[1])(zip(fizz, buzz, nums)))
writeln(num);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment