/// G. Hagopian - PPP5 Ex 11

/**
Write a program that writes out the first so many values
of the Fibonacci series, that is, the series that starts
with 1 1 2 3 5 8 13 21 34. The next number of the series
is the sum of the two previous ones. Find the largest
Fibonacci number that fits in an int.
*/

#include "std_lib_facilities.h"

bool next_fib(vector<uint64_t> &);
uint64_t rec_fib(uint64_t i);

int main() {
    uint64_t maxfib=2;
    vector<uint64_t> fib{1,1,2};
    while(next_fib(fib))
        cout << fib[fib.size()-1] << " ";
    uint64_t n{0};
    cout << "\nEnter an natural n, to compute Fib(n): ";
    while(cin >> n) {
        cout << rec_fib(n);
        cout << "\nEnter an natural n, to compute Fib(n): ";
    }
}

bool next_fib(vector<uint64_t> &fib) {
    uint64_t next = fib[fib.size()-1]+fib[fib.size()-2];
    if(next > fib[fib.size()-1]) {
       fib.push_back(next);
       return true;
    }
    return false;
}

uint64_t rec_fib(uint64_t i) {
    ///base cases
    if(i == 1 || i == 2)
        return 1;
    else return rec_fib(i-1) + rec_fib(i-2);
}
