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

😠 Grumpy

Squares a matrix. Complains about it.

Method
2Γ—2 matrix exponentiation
Language
C
Cost per term
O(log n) 2Γ—2 matrix products, fixed-width 64-bit integers
Display
Grumpy scoreboard
Furthest term
F(93), the largest value that fits in 64 bits, then it starts again at F(0)
Folder
fib-game/grumpy/
Pane
Grumpy's show

How it works

The matrix Q = [[1,1],[1,0]] raised to the power n holds F(n+1), F(n) and F(nβˆ’1). Repeated squaring gets Qⁿ in about logβ‚‚ n matrix products. Grumpy uses plain uint64 arithmetic, so the largest exact term is F(93) = 12,200,160,415,121,876,738.

The display

A stadium scoreboard. It prints the matrix Qⁿ, then F(n) in big block digits, then a new grumpy remark on every tick. A countdown runs at the bottom.

Pick a moment in the 75-second run. Each frame is a real colour capture of the pane.

Grumpy's show Β· t = 5 s

                GRUMPY SCOREBOARD   n = 7

                          Q^7 =
                        ⎑ 21  13 ⎀
                        ⎣ 13   8 ⎦

                           F(7)
                           β–ˆ β–ˆβ–ˆβ–ˆ
                           β–ˆ   β–ˆ
                           β–ˆ β–ˆβ–ˆβ–ˆ
                           β–ˆ   β–ˆ
                           β–ˆ β–ˆβ–ˆβ–ˆ

            Add the last two. Again. Riveting.
              70s left. Ctrl+C if you must.
Grumpy's show Β· t = 10 s

                GRUMPY SCOREBOARD   n = 14

                          Q^14 =
                       ⎑ 610  377 ⎀
                       ⎣ 377  233 ⎦

                          F(14)
                       β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆ
                         β–ˆ   β–ˆ   β–ˆ
                       β–ˆβ–ˆβ–ˆ   β–ˆ   β–ˆ
                         β–ˆ   β–ˆ   β–ˆ
                       β–ˆβ–ˆβ–ˆ   β–ˆ   β–ˆ

            Yes, it's still growing. Shocking.
              65s left. Ctrl+C if you must.
Grumpy's show Β· t = 20 s

                GRUMPY SCOREBOARD   n = 28

                          Q^28 =
                    ⎑ 514229  317811 ⎀
                    ⎣ 317811  196418 ⎦

                          F(28)
                 β–ˆβ–ˆβ–ˆ   β–ˆ β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆ   β–ˆ   β–ˆ
                   β–ˆ   β–ˆ   β–ˆ β–ˆ β–ˆ   β–ˆ   β–ˆ
                 β–ˆβ–ˆβ–ˆ   β–ˆ   β–ˆ β–ˆβ–ˆβ–ˆ   β–ˆ   β–ˆ
                   β–ˆ   β–ˆ   β–ˆ β–ˆ β–ˆ   β–ˆ   β–ˆ
                 β–ˆβ–ˆβ–ˆ   β–ˆ   β–ˆ β–ˆβ–ˆβ–ˆ   β–ˆ   β–ˆ

                  Is it 75 seconds yet?
              55s left. Ctrl+C if you must.
Grumpy's show Β· t = 35 s

                GRUMPY SCOREBOARD   n = 49

                          Q^49 =
               ⎑ 12586269025  7778742049 ⎀
               ⎣  7778742049  4807526976 ⎦

                          F(49)
         β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆ β–ˆ β–ˆ β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆ β–ˆ β–ˆ β–ˆβ–ˆβ–ˆ
           β–ˆ   β–ˆ   β–ˆ β–ˆ β–ˆ   β–ˆ β–ˆ β–ˆ   β–ˆ β–ˆ β–ˆ β–ˆ β–ˆ β–ˆ β–ˆ
           β–ˆ   β–ˆ   β–ˆ β–ˆβ–ˆβ–ˆ   β–ˆ β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆ β–ˆ β–ˆ β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆ
           β–ˆ   β–ˆ   β–ˆ β–ˆ β–ˆ   β–ˆ   β–ˆ β–ˆ   β–ˆ β–ˆ   β–ˆ   β–ˆ
           β–ˆ   β–ˆ   β–ˆ β–ˆβ–ˆβ–ˆ   β–ˆ   β–ˆ β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆ   β–ˆ β–ˆβ–ˆβ–ˆ

            Yes, it's still growing. Shocking.
              41s left. Ctrl+C if you must.
Grumpy's show Β· t = 50 s


                GRUMPY SCOREBOARD   n = 71

                          Q^71 =
           ⎑ 498454011879264  308061521170129 ⎀
           ⎣ 308061521170129  190392490709135 ⎦

                          F(71)
                     308061521170129
           (too long for big digits. Typical.)

               Don't look at me like that.
              25s left. Ctrl+C if you must.
Grumpy's show Β· t = 65 s


                GRUMPY SCOREBOARD   n = 92

                          Q^92 =
      ⎑ 12200160415121876738  7540113804746346429 ⎀
      ⎣  7540113804746346429  4660046610375530309 ⎦

                          F(92)
                   7540113804746346429
           (too long for big digits. Typical.)

               I squared a matrix for this.
              11s left. Ctrl+C if you must.
Grumpy's show Β· t = 72 s

                GRUMPY SCOREBOARD   n = 8

                          Q^8 =
                        ⎑ 34  21 ⎀
                        ⎣ 21  13 ⎦

                           F(8)
                         β–ˆβ–ˆβ–ˆ   β–ˆ
                           β–ˆ   β–ˆ
                         β–ˆβ–ˆβ–ˆ   β–ˆ
                         β–ˆ     β–ˆ
                         β–ˆβ–ˆβ–ˆ   β–ˆ

                 Sunflowers have it easy.
               4s left. Ctrl+C if you must.

The core code

From fib-game/grumpy/grumpy.c:

static Mat mul(Mat x, Mat y) {
    Mat r = { x.a*y.a + x.b*y.c, x.a*y.b + x.b*y.d,
              x.c*y.a + x.d*y.c, x.c*y.b + x.d*y.d };
    return r;
}

/* Q^n by repeated squaring */
static Mat qpow(unsigned n) {
    Mat r = {1, 0, 0, 1}, q = {1, 1, 1, 0};
    while (n) {
        if (n & 1) r = mul(r, q);
        q = mul(q, q);
        n >>= 1;
    }
    return r;
}

static uint64_t fib(unsigned n) { return (uint64_t)qpow(n).b; }

Run and check

fib-game/grumpy/run.sh            # the display, about 75 s
fib-game/grumpy/run.sh --verify   # first 30 terms and F(90) against known values

Limits and notes

← DocHappy β†’