Skip to content

Usage

H9A counts how many times a digit appears in an inclusive range of numbers. The default is the digit 9 in the range 1 to 100.

Command line

h9a [--digit DIGIT] [--start START] [--end END] [--json] [--no-color] [--screenshot [PATH]] [--version]

Examples:

h9a                                  # digit 9, range 1..100
h9a --digit 5 --start 1 --end 50     # digit 5, range 1..50
h9a --end 999                        # digit 9, range 1..999
h9a --json                           # machine-readable output
h9a --screenshot                     # write a PNG screenshot
h9a --no-color                       # plain output without colors

What the output means

The program prints the result in a fixed sequence of steps:

  1. Banner — "H9A" rendered with pyfiglet, with a subtitle describing the current digit and range.
  2. Per-place counts — for each decimal place with at least one match (ones, tens, hundreds, ...), the count is printed as a step.
  3. Total — the sum of all per-place counts.
  4. Explanation — a short breakdown with example numbers for each place, followed by the final result.

The number 99, for example, is counted once in the ones place and once in the tens place, which is why the default total is 20 and not 19.

Example run

 _   _  ___    _
| | | |/ _ \  / \
| |_| | (_) |/ _ \
|  _  |\__, / ___ \
|_| |_|  /_/_/   \_\


How Many 9 In 1 to 100

Calculating step by step...
Step 2: 9 appears 10 times in the ones place.
Step 3: 9 appears 10 times in the tens place.
Step 4: Total occurrences of 9 = 20.

Explanation:
1. In the ones place: The digit 9 appears in numbers like 9, 19, 29, ..., 99.
2. In the tens place: The digit 9 appears in numbers like 90, 91, 92, ..., 99.
3. Total occurrences are calculated by adding these together.

Final Result: In the range 1 to 100, the digit '9' appears 20 times!

JSON output

h9a --json
{
  "digit": 9,
  "start": 1,
  "end": 100,
  "by_position": {
    "1": 10,
    "10": 10
  },
  "total": 20
}

by_position maps each decimal place value (1, 10, 100, ...) to the number of times the digit appears there. total is the sum.

Screenshots

h9a --screenshot            # writes Screenshots/home.png
h9a --screenshot out.png    # writes out.png

Requires Pillow. See screenshots.md.

Exit codes

  • 0 — success
  • 2 — invalid arguments (for example a digit outside 0-9, or --start greater than --end)

No configuration files

H9A reads no environment variables and no configuration files; all settings are command-line options. See configuration.md.


Back to Home