C++, pasted on Jun 6:
 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 ``` ```/// Calculate F(N+1) from F(N) where /// F(N) is Nth Fibonacci number /// N > 10 #include #include #include using namespace std; /** * @brief Calculate next Fibonacci number in series from * previous Fibonacci. * * @param [in] lastFibonacci F(N) for N > 10 * @ret F(N+1) * * int_type should be integral type and not real. * If int_type is some big number type, it should provide * initialization from type double. */ template int_type findNextFibonacci(int_type lastFibonacci) { const double goldenRatio = 0.5 * sqrt(5.0) + 0.5; // FIXME: Change type to something more precise return static_cast(0.5 + goldenRatio * lastFibonacci); } static void testFindNextFibonacciFunctionFor(int number, int expected) { const int actual = findNextFibonacci(number); int len = 10; if(actual != expected) { cout << " *** ERROR *** "; len = 5; } cout << "Input = " << setw(len) << number << ", Expected = " << setw(len) << expected << ", Actual = " << setw(len) << actual << endl; } int main() { const int fibsize = 47; int fibs[fibsize] = {0, 1}; for(int i = 2; i < fibsize; ++i) { fibs[i] = fibs[i-1] + fibs[i-2]; } for(int i = 1; i < fibsize; ++i) { testFindNextFibonacciFunctionFor(fibs[i-1], fibs[i]); } // Let's test whether it works for Lucas numbers or not cout << endl; fibs[0] = 2; fibs[1] = 1; for(int i = 2; i < fibsize-2; ++i) { fibs[i] = fibs[i-1] + fibs[i-2]; } for(int i = 1; i < fibsize-2; ++i) { testFindNextFibonacciFunctionFor(fibs[i-1], fibs[i]); } return 0; } ```

Output:
 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 ``` ``` *** ERROR *** Input = 0, Expected = 1, Actual = 0 *** ERROR *** Input = 1, Expected = 1, Actual = 2 Input = 1, Expected = 2, Actual = 2 Input = 2, Expected = 3, Actual = 3 Input = 3, Expected = 5, Actual = 5 Input = 5, Expected = 8, Actual = 8 Input = 8, Expected = 13, Actual = 13 Input = 13, Expected = 21, Actual = 21 Input = 21, Expected = 34, Actual = 34 Input = 34, Expected = 55, Actual = 55 Input = 55, Expected = 89, Actual = 89 Input = 89, Expected = 144, Actual = 144 Input = 144, Expected = 233, Actual = 233 Input = 233, Expected = 377, Actual = 377 Input = 377, Expected = 610, Actual = 610 Input = 610, Expected = 987, Actual = 987 Input = 987, Expected = 1597, Actual = 1597 Input = 1597, Expected = 2584, Actual = 2584 Input = 2584, Expected = 4181, Actual = 4181 Input = 4181, Expected = 6765, Actual = 6765 Input = 6765, Expected = 10946, Actual = 10946 Input = 10946, Expected = 17711, Actual = 17711 Input = 17711, Expected = 28657, Actual = 28657 Input = 28657, Expected = 46368, Actual = 46368 Input = 46368, Expected = 75025, Actual = 75025 Input = 75025, Expected = 121393, Actual = 121393 Input = 121393, Expected = 196418, Actual = 196418 Input = 196418, Expected = 317811, Actual = 317811 Input = 317811, Expected = 514229, Actual = 514229 Input = 514229, Expected = 832040, Actual = 832040 Input = 832040, Expected = 1346269, Actual = 1346269 Input = 1346269, Expected = 2178309, Actual = 2178309 Input = 2178309, Expected = 3524578, Actual = 3524578 Input = 3524578, Expected = 5702887, Actual = 5702887 Input = 5702887, Expected = 9227465, Actual = 9227465 Input = 9227465, Expected = 14930352, Actual = 14930352 Input = 14930352, Expected = 24157817, Actual = 24157817 Input = 24157817, Expected = 39088169, Actual = 39088169 Input = 39088169, Expected = 63245986, Actual = 63245986 Input = 63245986, Expected = 102334155, Actual = 102334155 Input = 102334155, Expected = 165580141, Actual = 165580141 Input = 165580141, Expected = 267914296, Actual = 267914296 Input = 267914296, Expected = 433494437, Actual = 433494437 Input = 433494437, Expected = 701408733, Actual = 701408733 Input = 701408733, Expected = 1134903170, Actual = 1134903170 Input = 1134903170, Expected = 1836311903, Actual = 1836311903 *** ERROR *** Input = 2, Expected = 1, Actual = 3 *** ERROR *** Input = 1, Expected = 3, Actual = 2 *** ERROR *** Input = 3, Expected = 4, Actual = 5 *** ERROR *** Input = 4, Expected = 7, Actual = 6 Input = 7, Expected = 11, Actual = 11 Input = 11, Expected = 18, Actual = 18 Input = 18, Expected = 29, Actual = 29 Input = 29, Expected = 47, Actual = 47 Input = 47, Expected = 76, Actual = 76 Input = 76, Expected = 123, Actual = 123 Input = 123, Expected = 199, Actual = 199 Input = 199, Expected = 322, Actual = 322 Input = 322, Expected = 521, Actual = 521 Input = 521, Expected = 843, Actual = 843 Input = 843, Expected = 1364, Actual = 1364 Input = 1364, Expected = 2207, Actual = 2207 Input = 2207, Expected = 3571, Actual = 3571 Input = 3571, Expected = 5778, Actual = 5778 Input = 5778, Expected = 9349, Actual = 9349 Input = 9349, Expected = 15127, Actual = 15127 Input = 15127, Expected = 24476, Actual = 24476 Input = 24476, Expected = 39603, Actual = 39603 Input = 39603, Expected = 64079, Actual = 64079 Input = 64079, Expected = 103682, Actual = 103682 Input = 103682, Expected = 167761, Actual = 167761 Input = 167761, Expected = 271443, Actual = 271443 Input = 271443, Expected = 439204, Actual = 439204 Input = 439204, Expected = 710647, Actual = 710647 Input = 710647, Expected = 1149851, Actual = 1149851 Input = 1149851, Expected = 1860498, Actual = 1860498 Input = 1860498, Expected = 3010349, Actual = 3010349 Input = 3010349, Expected = 4870847, Actual = 4870847 Input = 4870847, Expected = 7881196, Actual = 7881196 Input = 7881196, Expected = 12752043, Actual = 12752043 Input = 12752043, Expected = 20633239, Actual = 20633239 Input = 20633239, Expected = 33385282, Actual = 33385282 Input = 33385282, Expected = 54018521, Actual = 54018521 Input = 54018521, Expected = 87403803, Actual = 87403803 Input = 87403803, Expected = 141422324, Actual = 141422324 Input = 141422324, Expected = 228826127, Actual = 228826127 Input = 228826127, Expected = 370248451, Actual = 370248451 Input = 370248451, Expected = 599074578, Actual = 599074578 Input = 599074578, Expected = 969323029, Actual = 969323029 Input = 969323029, Expected = 1568397607, Actual = 1568397607 ```