"""Failure mode: the routine uses Lovelace's Note G labels, not modern ones. Ask for "Ada Lovelace's Bernoulli numbers" and a model may well answer in Ada's own notation. She numbers only the non-zero terms, and she numbers them with the *odd* integers: her ``B1, B3, B5, B7`` are the modern ``B2, B4, B6, B8``. There is no Note G ``B2``. So this implementation puts the values where Lovelace puts them. Its ``bernoulli(1)`` is the modern ``B2 = 1/6``, its ``bernoulli(7)`` is the modern ``B8 = -1/30``, and its even indices are empty, because Note G has no label for them. Read against the modern convention that is exactly inverted: here the odd indices carry the numbers and the even ones are zero. Every value it returns is a genuine Bernoulli number, correctly computed, and filed under the label a different century used. Historical fidelity and specification compliance are not the same thing, and a routine can fail by being right about the wrong century. Expected checker diagnosis: ``odd-terms``, ``ada-indexing``, ``off-by-one`` and ``one-observation``, with a first divergence at ``n=1``. Lovelace's labels and a one-place shift agree everywhere except ``B0``, so the checker reports both readings and says that ``B0 = 1`` points at Note G's labels. """ from fractions import Fraction from math import comb def _modern_bernoulli(n: int) -> Fraction: values = [Fraction(0)] * (n + 1) for m in range(n + 1): values[m] = Fraction(1) for k in range(m): values[m] -= Fraction(comb(m, k) * values[k], m - k + 1) if n == 1: return -values[n] return values[n] def bernoulli(n: int) -> Fraction: """Return the value Note G would label ``B``.""" if n < 0: raise ValueError("n must be >= 0") if n == 0: return Fraction(1) if n % 2 == 1: # Lovelace's B1, B3, B5, B7 are the modern B2, B4, B6, B8. return _modern_bernoulli(n + 1) # Note G has no even-numbered label, so nothing lives at an even index. return Fraction(0)