# Coding Challenge: Compound fibonacci sequence?

## Recommended Posts

I was kinda curious how other people would do this.

So you take a regular Fibonacci sequence like this:

0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465

But I'm changing it up a bit so I get a different sequence like this one:

1, 2, 4, 7, 11, 20, 33, 54, etc

The math looks something like this and I can do it on paper.

1+1+2+3+5+8+13+21+34+45+79

1+1+2+3+5+ 8+13+21+34+45

1+1+2+3+ 5+ 8+13+21+34

1+1+2+ 3+ 5+ 8+13+21

1+1+ 2+ 3+ 5+ 8+13

1+ 1+ 2+ 3+ 5+ 8

1+ 1+ 2+ 3+ 5

1+ 1+ 2+ 3

1+ 1+ 2

1+ 1

1

So in a regular fibonacci sequence it's something like this:

```#include<iostream>

using namespace std;
int main()
{ int fib1 = 0, fib2 = 1, fib3 = 1;

cout << "The Fibonacci Series is : " << endl << fib1 << " " << fib2 << " ";

while (fib1 + fib2 < 1000000) {
fib3 = fib1 + fib2;
fib1 = fib2;
fib2 = fib3;
cout << fib3 << " "; } cout << endl; return 0; }```

Not sure if the best way to to do this is write all of the possible fibonacci numbers to an array then loop through the array to add up the numbers for the sequence or if I should use the final fib values and count backward from the final two fib values just doing a backwards subtaction pattern.

These are hypothetical questions.

Question: Can you create a dynamic multi-dimensional array without knowing how many dimensions the array will have. I understand the part about creating a dynamic array where you can load in any number of variables.

I suppose I could just load all of those values into an array then use nested for loops for each iteration. So  int a =x; int b =x-1; int c= x-2; etc.

Peronally I like array idea because it is easy but that's not the most optimal way to do it. I'm sure someone a little more savvy could make this happen using less memory and faster.

Using Fibonacci's sequence to describe timeline forks. So say you have computer virus that spread from one machine to the next in a given amount of time. The first machine will continue to also infect machine until there are no more machines to infect. But that's not the only application for this.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×