Skip to content

Instantly share code, notes, and snippets.

@pce
Last active August 8, 2020 23:46
Show Gist options
  • Save pce/7c43c537a38f9af10a02f930f1e792a6 to your computer and use it in GitHub Desktop.
Save pce/7c43c537a38f9af10a02f930f1e792a6 to your computer and use it in GitHub Desktop.
// g++ -std=c++11 fibo.cpp && ./a.out
#include <iostream>
#include <vector>
std::vector<int> f(std::vector<int> &v, int i, int n)
{
int j = 1;
if (i <= n) {
j = v.back();
v.push_back(i);
// std::cout << " j: " << j << "\n";
i = i + j;
f(v, i, n);
}
return v;
}
int main()
{
// starting with 1 and 1 rabbits
std::vector<int> v {1};
v = f(v, 1, 144);
std::cout << "\nf: 0";
for (const int i : v) {
std::cout << ", " << i;
}
std::cout << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment