// G. Hagopian -- PPP ex 3

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // std::swap

/*2. Write a function print() that prints a vector of ints to cout.
Give it two arguments: a string for “labeling” the output and a vector.
*/
//const char* cstring
void print(std::string cppstring, const std::vector<int64_t>& vi) {
	std::cout << cppstring << ":\n";
	for (int i = 0; i < vi.size() - 1; ++i) {
		std::cout << vi[i] << ", ";
	}
	std::cout << vi[vi.size() - 1];
}

/*3. Create a vector of Fibonacci numbers and print them using the
function from exercise 2. To create the vector, write a function,
fibonacci(x,y,v,n), where integers x and y are ints, v is an empty
vector<int>, and n is the number of elements to put into v;
v[0] will be x and v[1] will be y. A Fibonacci number is
one that is part of a sequence where each element is the sum
of the two previous ones. For example, starting with 1 and 2, we get
1, 2, 3, 5, 8, 13, 21, . . . .
Your fibonacci() function should make such a sequence starting
with its x and y arguments.
*/

void fibonacci(int64_t x, int64_t y, std::vector<int64_t>& f, unsigned int n) {
	f.push_back(x);
	f.push_back(y);
	for (int i = 2; i < n; ++i) {
		f.push_back(f[i - 2] + f[i - 1]);
	}
}

void reverse(std::vector<int64_t>& v) {
	for (int i = 0; i < v.size() / 2; ++i)
		std::swap(v[i], v[v.size() - 1 - i]);
}

void reverse1(std::vector<int64_t> f) {
	std::vector<int64_t> f2 = f;
	reverse(f2);
	print("reversed", f2);
}

int main() {
	//const char*
	int64_t x{ 0 }, y{ 0 };
	unsigned n{ 0 };
	std::string s = "Fibonacci";
	std::vector<int64_t> v;
	std::cout << "\nWhat is the first two of your Fibonacci sequence? ";
	std::cin >> x >> y;
	std::cout << "\nHow many are in the sequence (>2): ";
	//std::cout << "\nNote anything too large will result in a wrap-around error"
	//	<< "\nMAXINT = 2^31-1 = 2147483647 = " << INT32_MAX;
	std::cin >> n;
	fibonacci(x, y, v, n);
	std::cout << "\nHere's your sequence: ";
	print(s, v);
	std::cout << std::endl;
	reverse1(v);
	std::cin.ignore(); // clear the buffer?
	std::cin.get();
}

