πŸŒ€ Fibonacci Game
Source: Notion task β€œPublish the Fibonacci Game site on the public site” (private notes) Β· code in fib-game/ Β· built 2026-11-24

The 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

MethodCore ideaWork for F(n)Trade-off
Iterative (Happy)a, b = b, a + bO(n) additionsEvery term in order; simplest; ideal for streaming.
Matrix power (Grumpy)[[1,1],[1,0]]ⁿO(log n) matrix productsJumps 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) multiplicationsLike the matrix method, with fewer multiplications. Big ints, so no cap.
Binet (Sleepy)round(φⁿ / √5)One power, precision ∝ nA 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).

F(n)/F(nβˆ’1) swings above and below Ο† and closes in on it; the error shrinks by a factor of about 2.6 per step1.001.251.501.752.00Ο† β‰ˆ 1.618n=2: 1/1 = 1.000000n=3: 2/1 = 2.000000n=4: 3/2 = 1.500000n=5: 5/3 = 1.666667n=6: 8/5 = 1.600000n=7: 13/8 = 1.625000n=8: 21/13 = 1.615385n=9: 34/21 = 1.619048n=10: 55/34 = 1.617647n=11: 89/55 = 1.618182n=12: 144/89 = 1.617978n=13: 233/144 = 1.618056n=14: 377/233 = 1.618026n=15: 610/377 = 1.618037251015nF(n)/F(nβˆ’1)1e01e-41e-81e-121e-16n=2: |ratio βˆ’ Ο†| = 6.18e-01n=5: |ratio βˆ’ Ο†| = 4.86e-02n=8: |ratio βˆ’ Ο†| = 2.65e-03n=11: |ratio βˆ’ Ο†| = 1.48e-04n=14: |ratio βˆ’ Ο†| = 8.24e-06n=17: |ratio βˆ’ Ο†| = 4.59e-07n=20: |ratio βˆ’ Ο†| = 2.56e-08n=23: |ratio βˆ’ Ο†| = 1.43e-09n=26: |ratio βˆ’ Ο†| = 7.95e-11n=29: |ratio βˆ’ Ο†| = 4.43e-12n=32: |ratio βˆ’ Ο†| = 2.47e-13n=35: |ratio βˆ’ Ο†| = 1.38e-14n=38: |ratio βˆ’ Ο†| = 7.66e-16210203040n|F(n)/F(nβˆ’1) βˆ’ Ο†| (log scale)

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.

The number of digits in F(n) grows in a straight line, about one digit every 4.8 steps01020304064-bit limit (2⁢⁴ β‰ˆ 1.8 Γ— 10¹⁹)Sleepy reached F(24), 5 digitsSleepy F(24)Grumpy reached F(93), 20 digitsGrumpy F(93)Happy reached F(94), 20 digitsHappy F(94)150100150200ndigits in F(n)Doc went off the chart: F(20,000,000) has 4,179,753 digits

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.

Largest index each dwarf reached in 75 seconds, on a log scale10⁰10Β²10⁴10⁢10⁸πŸ§ͺ DocDoc: n = 20,000,000n = 20,000,000🌈 HappyHappy: n = 94n = 94😠 GrumpyGrumpy: n = 93n = 93😴 SleepySleepy: n = 24n = 24

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
← The show