"""Unit-prefix cost of a cache write plus later reads.

Multipliers are the ones stated on Anthropic's pricing page:
5-minute write 1.25x, 1-hour write 2x, cache read 0.1x.
A unit prefix costs 1 with no cache. This is not an invoice.
"""


def cached(write: float, reads: int, hit: float = 0.1) -> float:
    return write + reads * hit


def uncached(reads: int) -> float:
    return 1 + reads


def main() -> None:
    print("reads uncached cache5m cache1h")
    for reads in (0, 1, 2, 3):
        print(
            f"{reads:5d} {uncached(reads):8.2f} {cached(1.25, reads):7.2f} {cached(2.0, reads):7.2f}"
        )
    # first n where cached strictly beats uncached
    for name, write in (("5m", 1.25), ("1h", 2.0)):
        n = 0
        while cached(write, n) >= uncached(n):
            n += 1
            if n > 10:
                break
        print(f"pays_off_after_reads_{name}={n}")


if __name__ == "__main__":
    main()
