Skip to content

Instantly share code, notes, and snippets.

@cdriper
Last active January 7, 2023 06:24
Show Gist options
  • Select an option

  • Save cdriper/cff95adb29d08be83616d250b84dd4d3 to your computer and use it in GitHub Desktop.

Select an option

Save cdriper/cff95adb29d08be83616d250b84dd4d3 to your computer and use it in GitHub Desktop.
generator<pair<int, int>> fibonacci(int n)
{
int a = 0;
int b = 1;
for ( auto i : ranges::iota_view{1, n+1} )
{
co_yield make_pair(i, a);
auto tmp = a;
a = b;
b += tmp;
}
}
int main()
{
for( auto p : fibonacci(10) )
{
cout << format("{} {}", p.first, p.second) << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment