Skip to content

Instantly share code, notes, and snippets.

@crioux
Created September 17, 2017 06:07
Show Gist options
  • Save crioux/c30c50a01886cb9e56ff6894762afa5a to your computer and use it in GitHub Desktop.
Save crioux/c30c50a01886cb9e56ff6894762afa5a to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
struct F
{
int x, e, t, f;
F(int n, int i = 1) : x(i), e(n), t(1), f(1) {}
F begin() { return F(e); }
F end() { return F(e, e); }
F &operator++()
{
x++;
t = (t + 1) % 3;
f = (f + 1) % 5;
return *this;
}
bool operator!=(F o) { return x != o.x; }
std::string operator*()
{
return (t && f) ? std::to_string(x) : !t && !f ? "fizzbuzz" : !t ? "fizz" : "buzz";
}
};
F fizzbuzz(int n) { return F(n); }
int main(int argc, char **argv)
{
size_t n = 1000;
for (std::string s : fizzbuzz(n))
{
std::cout << s << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment