Skip to content

A generalized solver program for a coin-based math puzzle from Parade magazine

License

Notifications You must be signed in to change notification settings

caleb531/coin-problem

Repository files navigation

Coin Problem

Copyright 2019-2025 Caleb Evans
Released under the MIT license

Inspiration

This project was inspired by a math problem posed to Parade magazine's Marilyn Vos Savant in November 2019:

In a contest, a friend guessed the exact number of coins in a jar: 1,692. She won all of the coins, which totaled $100.54. They consisted of pennies, nickels, dimes and quarters. How many coins of each kind were in the jar?

Source: https://parade.com/951440/marilynvossavant/can-you-solve-this-coin-riddle/

This project serves as a generalized solver program given any number of coins and any dollar amount.

Usage

Install uv

This project uses uv to manage the virtual environment and project dependencies. You can install it like so:

curl -LsSf https://astral.sh/uv/install.sh | sh

Set up environment and install dependencies

uv sync

Run solver program

uv run -m coinproblem -c 1692 -a 100.54

Options

  • --total-coin-count / -c: The total number of coins (i.e. the coin count)
  • --total-coin-amount / -a: the total dollar value of all coins combined (i.e. the coin amount)

Run duel program

The referee program accepts a variable number of executables that will be pit against each other. The referee program must be run as a module via the python -m command.

Please refer to the Player Program Specification to learn how to write your own player programs.

uv run -m coinproblem.referee ./coinproblem/my-player.py

Options

  • --timeout / -t (default: 10): The number of seconds each player will run before timing out
  • --min-count / --min (default: 0): The minimum number of coins per coin type to be generated
  • --max-count/ --max (default: 100): The maximum number of coins per coin type to be generated

Run tests

uv run pytest --cov --cov-report=term-missing

To add additional test cases, please append an array of [penny, nickel, dime, quarter] counts to the JSON array in test_cases.json.

About

A generalized solver program for a coin-based math puzzle from Parade magazine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages