fib-game/ Β· built 2026-11-24The maths
The same sequence, four ways. The numbers below come from computing the sequence again for this page; they match all four dwarves' verified output.
Four methods compared
| Method | Core idea | Work for F(n) | Trade-off |
|---|---|---|---|
| Iterative (Happy) | a, b = b, a + b | O(n) additions | Every term in order; simplest; ideal for streaming. |
| Matrix power (Grumpy) | [[1,1],[1,0]]βΏ | O(log n) matrix products | Jumps to F(n); fixed 64-bit ints cap it at F(93). |
| Fast doubling (Doc) | F(2k), F(2k+1) from F(k), F(k+1) | O(log n) multiplications | Like the matrix method, with fewer multiplications. Big ints, so no cap. |
| Binet (Sleepy) | round(ΟβΏ / β5) | One power, precision β n | A formula, no loop over terms; needs enough decimal digits to round exactly. |
The ratio closes in on Ο
Doc's ledger and Happy's spiral both rest on one fact: F(n)/F(nβ1) tends to the golden ratio Ο = (1 + β5)/2 β 1.6180339887. The ratio swings above and below Ο (left). The error shrinks by a factor of about ΟΒ² β 2.6 at every step, which is a straight line on a log scale (right).
How fast the numbers grow
F(n) has about n Γ logββ Ο β 0.209 n digits, so the digit count grows in a straight line. Dots mark the furthest term of three dwarves. The red line is why Grumpy stops at F(93): F(94) does not fit in 64 bits.
How far each dwarf got in 75 seconds
Speed was not the goal; each dwarf paced its display for the show. Still, the method shapes the reach. Doc's fast doubling jumped to F(20,000,000). Sleepy types slowly on purpose. The scale is logarithmic.
Binet's formula
Sleepy's method in one line, where Ο = (1 + β5)/2 and Ο = (1 β β5)/2:
F(n) = (ΟβΏ β ΟβΏ) / β5 = round(ΟβΏ / β5) because |ΟβΏ / β5| < Β½ for every n β₯ 0