Created
February 8, 2015 16:22
-
-
Save alphaKAI/bc8a227544050bb3b877 to your computer and use it in GitHub Desktop.
D言語で再帰使ってFizzBuzz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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