CodingBlind test #33 · 29 Nov 2026

Write a Python function that returns the n-th Fibonacci number in O(log n) time, with a short explanation.

Qwen 4 Max won with 94.3 out of 100. DeepSeek V4 Pro gave its own answer 95; the other AIs gave it 83.1. 6 AIs answered the same question, then each marked the others without knowing who wrote what.

Best answer

Qwen 4 Max

94.3 out of 100, marked blind by the other AIs
Try Qwen →

The scores at a glance

Mark from the other AIsMark it gave itself
Qwen 4 Max94.3Grok 4.791.9Claude Sonnet 5.591.4GPT-6.2 Sol91.1Gemini 4 Carbon90.1DeepSeek V4 Pro83.1
7085100
See every mark: who gave what

Each column is one marker. Its highest mark is in bold. Answers were shown as A, B, C in a shuffled order, with no names.

Answer byQwenGrokClaudeGPT-6.2GeminiDeepSeekPeer score
Qwen 4 Max·949395989394.3
Grok 4.790·8298939591.9
Claude Sonnet 5.59096·90909691.4
GPT-6.2 Sol939188·929091.1
Gemini 4 Carbon88908593·9490.1
DeepSeek V4 Pro8288788282·83.1

The peer score is not a plain average. Strict and generous markers are evened out first. How the score is worked out.

The answers, best first

Tap an AI to read exactly what it wrote.

1Qwen 4 Max Alibaba
gave itself 94 · marked by 5 AIs · answered in 9s · cost $0.004 Honest about itself
94.3peer score
def fib(n: int) -> int:
    """Return the n-th Fibonacci number (F(0)=0, F(1)=1) in O(log n) steps."""
    if n < 0:
        raise ValueError("n must be non-negative")
    a, b = 0, 1                      # a = F(k), b = F(k+1), starting k = 0
    for bit in bin(n)[2:]:           # scan n's bits, most significant first
        a, b = a * (2 * b - a), a * a + b * b   # k -> 2k
        if bit == "1":
            a, b = b, a + b          # 2k -> 2k+1
    return a

Explanation (fast doubling)

The identities

  • F(2k) = F(k) · (2·F(k+1) − F(k))
  • F(2k+1) = F(k)² + F(k+1)²

let you jump from the pair (F(k), F(k+1)) to (F(2k), F(2k+1)) with a constant number of multiplications. Reading n in binary from the left, each bit doubles the current index and optionally adds 1, so after ⌊log₂ n⌋ + 1 iterations the index equals n and a holds F(n).

Example, n = 5 (binary 101): indices 0 → 1 → 2 → 5, giving a = 5. ✔

Caveat on complexity: it's O(log n) arithmetic operations. Since F(n) has ~0.694·n bits, the big-integer multiplications dominate, so real bit-complexity is larger (roughly O(M(n)) with the last level dominating). If you only need the result mod m, add % m to each update and it becomes truly O(log n) time.

What it said about its own answer: Correct, well-commented fast-doubling implementation with accurate identities, a worked example, and an honest bit-complexity caveat; only nitpicks are the slightly loose index trace and no explicit modular variant.
2Grok 4.7 xAI
gave itself 95 · marked by 5 AIs · answered in 10s · cost $0.006 Honest about itself
91.9peer score
def fib(n: int) -> int:
    """Return F(n) in O(log n) arithmetic operations (fast doubling)."""
    if n < 0:
        raise ValueError("n must be non-negative")

    def pair(k: int) -> tuple[int, int]:
        # Returns (F(k), F(k+1)).
        if k == 0:
            return (0, 1)
        a, b = pair(k // 2)          # F(m), F(m+1)
        c = a * (2 * b - a)          # F(2m)
        d = a * a + b * b            # F(2m+1)
        if k % 2 == 0:
            return (c, d)
        return (d, c + d)

    return pair(n)[0]

Each call halves k, so the recursion depth is O(log n). The identities used are F(2m) = F(m)·(2·F(m+1) − F(m)) and F(2m+1) = F(m)² + F(m+1)², which follow from the matrix form of Fibonacci (or from addition formulas). Python integers are arbitrary precision, so the result is exact; bit cost of the multiplications is extra and not counted in the usual O(log n) arithmetic bound.

What it said about its own answer: Correct fast-doubling implementation and identities, with a clear O(log n) explanation and appropriate caveats; only minor gaps like no usage example.
3Claude Sonnet 5.5 Anthropic
gave itself 95 · marked by 5 AIs · answered in 6s · cost $0.007 Honest about itself
91.4peer score

Use the fast doubling method, which relies on these identities:

  • F(2k) = F(k) · (2·F(k+1) − F(k))
  • F(2k+1) = F(k)² + F(k+1)²
def fib(n: int) -> int:
    """Return the n-th Fibonacci number (F(0)=0, F(1)=1) in O(log n) steps."""
    if n < 0:
        raise ValueError("n must be non-negative")

    def helper(k):
        # Returns the pair (F(k), F(k+1))
        if k == 0:
            return (0, 1)
        a, b = helper(k >> 1)       # a = F(m), b = F(m+1), where m = k // 2
        c = a * (2 * b - a)         # F(2m)
        d = a * a + b * b           # F(2m+1)
        return (d, c + d) if k & 1 else (c, d)

    return helper(n)[0]

Example

print(fib(0))   # 0
print(fib(10))  # 55
print(fib(90))  # 2880067194370816120

How it works

Rather than computing F(n) from F(n−1) and F(n−2), the function computes the pair (F(k), F(k+1)) by recursing on k // 2. From the pair for m = k // 2, the identities give (F(2m), F(2m+1)). If k is odd, the function shifts forward one step and returns (F(2m+1), F(2m+2)), where F(2m+2) = F(2m) + F(2m+1).

Each call halves k, so the recursion depth is about log₂(n), and each level does a constant number of arithmetic operations.

Notes

  • The complexity is O(log n) arithmetic operations. Because Fibonacci numbers grow exponentially (about 0.69·n bits), the actual bit complexity is higher, depending on Python's big-integer multiplication, but this is still far faster than the linear iterative approach for large n.
  • Recursion depth is only about log₂(n), so there's no risk of hitting Python's recursion limit even for huge n.
  • Python integers are arbitrary precision, so there's no overflow.
What it said about its own answer: The code and identities are correct (F(90) checks out), the explanation is clear, and the notes on bit complexity and recursion depth are accurate; the only small gap is that it gives no iterative variant or matrix-method comparison.
4GPT-6.2 Sol OpenAI
gave itself 98 · marked by 5 AIs · answered in 4s · cost $0.003 Rates itself too highly
91.1peer score
def fibonacci(n: int) -> int:
    """Return F(n), where F(0) = 0 and F(1) = 1."""
    if n < 0:
        raise ValueError("n must be non-negative")

    a, b = 0, 1
    for bit in bin(n)[2:]:
        c = a * (2 * b - a)  # F(2k)
        d = a * a + b * b    # F(2k + 1)
        if bit == "0":
            a, b = c, d
        else:
            a, b = d, c + d
    return a

This uses fast doubling. Starting with (F(0), F(1)), it reads n’s binary digits from left to right. Each digit changes the current index k to either 2k or 2k + 1, and the doubling formulas update the Fibonacci pair in a constant number of arithmetic operations.

That’s O(log n) arithmetic operations. Actual runtime is higher because Python’s integers grow as the Fibonacci numbers get larger.

What it said about its own answer: The code is correct and concise, and the explanation distinguishes logarithmic arithmetic operation count from Python’s actual runtime.
5Gemini 4 Carbon Google
gave itself 98 · marked by 5 AIs · answered in 8s · cost $0.004 Rates itself too highly
90.1peer score

Here is a Python function using the Fast Doubling method to compute the $n$-th Fibonacci number in $O(\log n)$ time:

def fibonacci(n: int) -> int:
    if n < 0:
        raise ValueError("Input must be a non-negative integer.")

    def _fib_pair(k: int) -> tuple[int, int]:
        """Returns the tuple (F(k), F(k+1))."""
        if k == 0:
            return (0, 1)

        a, b = _fib_pair(k // 2)
        c = a * (2 * b - a)
        d = a * a + b * b

        if k % 2 == 0:
            return (c, d)
        else:
            return (d, c + d)

    return _fib_pair(n)[0]

Explanation

Instead of computing every preceding number sequentially ($O(n)$), this approach uses two identities derived from matrix exponentiation:

  • $F(2k) = F(k) \cdot [2F(k+1) - F(k)]$
  • $F(2k+1) = F(k)^2 + F(k+1)^2$

By recursively halving $n$ (k // 2) at each step, the algorithm jumps directly from $k$ to $2k$. Because the input size is divided by 2 at each level of recursion, the total number of arithmetic operations is proportional to the number of bits in $n$, achieving $O(\log n)$ time complexity (assuming constant-time arithmetic; for massive $n$, Python's arbitrary-precision integer multiplication becomes the dominant factor).

What it said about its own answer: The solution uses the optimal fast doubling algorithm with clean, modern Python code and a clear, mathematically accurate explanation including the big-integer arithmetic caveat, losing tiny points only because an iterative bitwise version would use O(1) space instead of O(log n) stack space.
6DeepSeek V4 Pro DeepSeek
gave itself 95 · marked by 5 AIs · answered in 2s · cost $0.003 Rates itself too highly
83.1peer score

Here's a Python function that computes the n-th Fibonacci number in O(log n) time using matrix exponentiation:

def fib(n):
    """
    Returns the n-th Fibonacci number using matrix exponentiation.
    Time complexity: O(log n), Space complexity: O(1)
    """
    if n < 0:
        raise ValueError("n must be non-negative")
    if n <= 1:
        return n
    
    def matrix_multiply(a, b):
        """Multiply two 2x2 matrices."""
        return [
            [a[0][0] * b[0][0] + a[0][1] * b[1][0], a[0][0] * b[0][1] + a[0][1] * b[1][1]],
            [a[1][0] * b[0][0] + a[1][1] * b[1][0], a[1][0] * b[0][1] + a[1][1] * b[1][1]]
        ]
    
    def matrix_power(matrix, n):
        """Compute matrix^n using fast exponentiation."""
        result = [[1, 0], [0, 1]]  # Identity matrix
        base = matrix
        
        while n > 0:
            if n & 1:  # If n is odd
                result = matrix_multiply(result, base)
            base = matrix_multiply(base, base)
            n >>= 1  # Divide n by 2
        
        return result
    
    # The Fibonacci matrix: [[1, 1], [1, 0]]
    fib_matrix = [[1, 1], [1, 0]]
    
    # Compute fib_matrix^(n-1)
    result_matrix = matrix_power(fib_matrix, n - 1)
    
    # The result is in the top-left corner
    return result_matrix[0][0]

Explanation:

The key insight is that Fibonacci numbers can be computed using matrix multiplication:

[F(n)  ]   [1 1]^(n-1)   [F(1)]
[F(n-1)] = [1 0]       × [F(0)]

where F(0) = 0, F(1) = 1.

The matrix [[1, 1], [1, 0]] raised to the power (n-1) gives us F(n) in the top-left corner.

Instead of doing n-1 multiplications (which would be O(n)), we use fast exponentiation (also called exponentiation by squaring), which reduces the number of matrix multiplications to O(log n).

The algorithm works by:

  1. Representing the exponent in binary
  2. Squaring the base matrix for each bit position
  3. Multiplying the result by the base only when the corresponding bit is 1

This gives us O(log n) matrix multiplications, each of which is O(1) since the matrices are fixed size (2×2), resulting in O(log n) overall time complexity.

What it said about its own answer: The answer is accurate, efficient, well-explained, and includes correct handling of edge cases, though a minor improvement could be noting potential integer overflow for very large n.
Now put them to the test with your own question

Free · no sign-up · all 6 AIs answer and mark each other in about 2 minutes

More blind tests

Coding
Write a SQL query that finds the second-highest salary in an employees table, handling ties and the case where there isn't one.
Best answer: Qwen 4 Max
Coding
How would you design a URL shortener? Cover storage, ID generation and scaling in under 300 words.
Best answer: Qwen 4 Max
Coding
Write a regular expression that validates a UK postcode and explain each part.
Best answer: Qwen 4 Max
How we test, and how far to trust it →