Skip to content

Instantly share code, notes, and snippets.

@alphaKAI
Created February 8, 2015 16:22
Show Gist options
  • Select an option

  • Save alphaKAI/bc8a227544050bb3b877 to your computer and use it in GitHub Desktop.

Select an option

Save alphaKAI/bc8a227544050bb3b877 to your computer and use it in GitHub Desktop.
D言語で再帰使ってFizzBuzz
import std.stdio,
std.conv,
std.algorithm;
string[] fizzbuzz(int max, int i = 0, string[] base = null){
return max == 0 ? base : fizzbuzz(max - 1, ++i, base ~ {
return !(i % 15) ? "FizzBuzz" :
!(i % 3) ? "Fizz" :
!(i % 5) ? "Buzz" : i.to!string;
}());
}
void main(){
foreach(e; 30.fizzbuzz)
e.writeln;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment