H9A counts how many times a digit (0–9) appears across any range of numbers. Unlike brute-force scripts, it uses a closed-form O(log n) algorithm, so a range from 1 to 1,000,000,000,000 returns instantly. It prints a colorized, step-by-step breakdown of each decimal place, supports machine-readable JSON, and can render terminal-style screenshots.
Wispr Flow: Dictation That Works EverywhereStop typing. Start speaking. 4x faster.
Promoted
Maker
📌
H9A started as the classic puzzle "How many 9s are in 1–100?" (the answer is 20, and 99 counts twice). I turned it into a proper little Python package: a `h9a` CLI plus an importable library returning a per-place breakdown.
Highlights:
- O(log n) closed-form counting — no range iteration, so huge ranges are instant
- Step-by-step explanation of every decimal place (ones, tens, hundreds, ...)
- `--json` output for scripting, `--no-color` for terminals without ANSI
- `--screenshot` renders the output to a PNG with Pillow
- 74 tests, ruff + mypy + pre-commit, CI docs and container publishing
Install: `pip install h9a`
Docs: https://rkriad585.github.io/h9a/
Source: https://github.com/rkriad585/h9a