A Flask web app and JSON REST API that returns the optimal (fewest pieces) USD coin and bill breakdown for any dollar amount.
| Bill / Coin | Value |
|---|---|
| Hundred Dollar Bill | $100.00 |
| Fifty Dollar Bill | $50.00 |
| Twenty Dollar Bill | $20.00 |
| Ten Dollar Bill | $10.00 |
| Five Dollar Bill | $5.00 |
| Two Dollar Bill | $2.00 |
| One Dollar Bill | $1.00 |
| Half Dollar | $0.50 |
| Quarter | $0.25 |
| Dime | $0.10 |
| Nickel | $0.05 |
| Penny | $0.01 |
GET /api/v1/change?amount=<value>
Example:
curl "http://localhost:5000/api/v1/change?amount=1.23"{
"total": "1.23",
"change": [
{"denom_name": "One Dollar Bill", "count": 1, "denom_amount": "1.00"},
{"denom_name": "Dime", "count": 2, "denom_amount": "0.10"},
{"denom_name": "Penny", "count": 3, "denom_amount": "0.01"}
]
}| Status | Condition |
|---|---|
200 |
Valid amount |
400 |
Missing, non-numeric, or non-positive amount |
Requires Cursor or VS Code with the Dev Containers extension, plus OrbStack or Docker Desktop.
- Open the repo root in Cursor / VS Code.
- When prompted, click Reopen in Container — or run
Dev Containers: Reopen in Containerfrom the command palette. - The container builds once, then
postCreateCommandinstalls the project and dev tools automatically.
Inside the container a custom prompt shows your git context:
sample_code_1 | master | ~/workspace/sample_code_1 $
Useful shell shortcuts pre-loaded:
| Alias | Command |
|---|---|
serve |
flask run (binds 0.0.0.0:5000) |
run-tests |
pytest -v |
lint |
ruff check . |
typecheck |
mypy sample_1 |
check |
lint + typecheck + tests in sequence |
dc |
docker compose |
python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
flask --app sample_1.app run --debugCopy the env file first:
cp example.env .envDevelopment (live-reload, mounts source):
docker compose --profile dev up --buildProduction (multi-stage build, gunicorn, non-root user):
docker compose --profile prod up -d --buildBrowse to http://localhost:5000.
pytest -vThe suite covers denomination correctness, edge cases (zero, negative), and the classic float-precision trap (1.15 * 100 = 114.999… in float arithmetic — handled with Decimal throughout).
GitHub Actions runs on every push and pull request to master:
- test — ruff lint → mypy type-check → pytest
- docker — builds the production image (only runs if tests pass)
Contributions are accepted in forms of employment or large sums of money.