Created
July 3, 2012 07:31
-
-
Save rhysd/3038277 to your computer and use it in GitHub Desktop.
FizzBuzz
This file contains 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
#include <iostream> | |
#include <array> | |
#include <string> | |
#include <algorithm> | |
#include <numeric> | |
int main() | |
{ | |
std::array<size_t, 100> arr; | |
std::iota(arr.begin(), arr.end(), 1); | |
std::array<std::string, 100> fizzbuzz; | |
std::transform(arr.begin(), arr.end(), fizzbuzz.begin(), | |
[](size_t const i) -> std::string | |
{ | |
return i%15==0 ? "FizzBuzz" : | |
i%3==0 ? "Fizz" : | |
i%5==0 ? "Buzz" : | |
/*else*/ std::to_string(i); | |
} | |
); | |
std::for_each(fizzbuzz.begin(), fizzbuzz.end(), | |
[](std::string const& str) | |
{ | |
std::cout << str << std::endl; | |
} | |
); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment