Login
You're viewing the techdon.dev public feed.
  • Oct 13, 2026, 7:53 PM

    2/ I wanted to do this one for the AI idiot, but it was too long.

    It's the same iterative matrix power fibonacci O(log n) algorithm just with the matrix power operation spelled out in a loop. One could complain, "It doesn't even have any + operation. It's obviously wrong."

    The iterative matrix power fibonacci O(log n) algorithm just with the matrix power operation spelled out in a loop. One could complain, "It doesn't even have any + operation. It's obviously wrong."

```rust
fn fib(mut n: u32) -> u32 {
    let mut a = Mat2::identity();
    let mut b = Mat2::new(
        1u32, 1, 1, 0
    );
    while n > 0 {
        if n & 1 != 0 {
            a *= b;
        }
        b *= b;
        n >>= 1;
    }
    a[(0, 1)]
}
```
    💬 0🔄 0⭐ 3