Cody

Problem 44628. The other half of the Fibonacci sequence

Created by David Verrelli in Community

The "Fibonacci sequence" — F = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, ...] — appeared in Indian mathematical expositions from circa 700 CE or earlier, and in the writings of Leonardo of Pisa (a.k.a. "Fibonacci") circa 1202 CE.

This sequence can be defined by

F(n+2) = F(n+1) + F(n)

in which F(1) = 1, F(2) = 1, F(3) = 2, ....

Later in history, it was recognised that F(0) = 0. Of course, this still satisfies the formula in bold above [for n=0]: F(2) = F(1) + F(0).

Your job in this Cody Problem is to 'create history'(?) by extending this sequence to negative values of n, to discover the missing half of this sequence!

EXAMPLE:

If n=-1, then F(-1) must be 1, to ensure that F(1) = F(0) + F(-1) — thus satisfying the formula in bold above.

You are only required to provide outputs for n < 3 that can be represented by an int64 data type. To enforce this, your output needs to be of this data type.

Solution Stats

30.0% Correct | 70.0% Incorrect
Last solution submitted on Feb 19, 2019