Floating Mountain Stability
The scientists now believe that the sizes of the stacked mountains did follow generalized Fibbonacci sequence property originally (when they were formed), but they believe that some of the mountains in the structures may have been destroyed or may have drifted apart. They further observed that at most 9 consecutive mountains in the stack may be removed without compromising the stability of the structure. They are now trying to verify this new conjecture.
You are to write a program for this purpose. Specifically, given a sequence of numbers, some of which may be negative, you must determine if the numbers are part of a generalized Fibbonacci sequence (let’s call it the original sequence), such that all consecutive pairs of numbers in the input sequence are less than 10 apart (i.e., fewer than 9 items between any consecutive pair of numbers) in the original generalized Fibbonacci sequence.
As an example, the sequence: 0 6 16, follows this property because the numbers are from the following generalized Fibbonacci sequence:
and 0 & 6 are only 4 numbers apart in the generalized sequence.
As another example: the sequence -22 8 77 125, also satisfies the property. Here is the corresponding generalized Fibbonacci sequence:
3 3 0 6 16 4 -22 8 77 125 4 1 1 1 1
STABLE 0 2 2 4 6 STABLE -22 15 -7 8 1 UNSTABLE