Skip to content
webtype.orgwebtype.org#265 greater-than · par 4

    ↑↓ move · ⏎ open · esc close

    No. 265 · September 17, 2026 · Hard

    Which is bigger

    Implement `GreaterThan<A, B>` so it is `true` when `A` is strictly greater than `B`, and `false` otherwise. Both are non-negative whole numbers.

    01

    Try the puzzle yourself

    Par 4

    Puzzle

    greater-than.ts
    Stroke 1 of 4Not run yet

    Replace ??? — your solution is checked against the cases below. Tab indents; press Escape then Tab to move focus out.

    Checks

    4
    • GreaterThan<3, 1>
      true
    • GreaterThan<1, 3>
      false
    • GreaterThan<2, 2>
      false
    • GreaterThan<0, 5>
      false

    How a check is judged Exact type equality, not assignability — an intersection is not the same as the flattened object.

    How everyone did

    Fewer than 5 people have solved this one so far. The distribution appears once there is enough of a sample to mean anything.

    Short game

    Fewest characters

    No public scores yet.

    Archive
    02

    Annotated solution

    Published September 18, 2026

    The solution

    type GreaterThan<A extends number, B extends number, C extends unknown[] = []> =
      C['length'] extends A
        ? false
        : C['length'] extends B
          ? true
          : GreaterThan<A, B, [...C, unknown]>

    The common wrong answer

    type GreaterThan<A extends number, B extends number, C extends unknown[] = []> =
      C['length'] extends B
        ? true
        : C['length'] extends A
          ? false
          : GreaterThan<A, B, [...C, unknown]>

    Both tests are right; the order is not. When `A` and `B` are equal the counter reaches them on the same step, and whichever question is asked first wins. Asking about `B` first answers `true` for `GreaterThan<2, 2>` — equal is reported as greater, and only the equality case ever reveals it.

    Line by line

    1. C['length'] extends A ? false

      Reaching `A` first means `B` is at least as large, so `A` cannot be strictly greater. Putting this branch first is what makes the comparison strict rather than "greater or equal".

    2. [...C, unknown]

      One tick of the counter. The tuple is never read — only its length is — so it is the cheapest possible way to hold a number that can go up by one.

    3. GreaterThan<0, 5>

      The counter starts at zero, so this is decided before a single step is taken: `A` is reached immediately and the answer is `false`.

    Takeaway

    When two conditions can fire on the same step, their order is the specification. Comparison types are almost always correct on the unequal cases and wrong on the tie.

    Uses