Skip to content

Instantly share code, notes, and snippets.

@JosephTLyons
Last active February 22, 2024 21:12
Show Gist options
  • Save JosephTLyons/5c95abc5758fd68e73303726f65f96f1 to your computer and use it in GitHub Desktop.
Save JosephTLyons/5c95abc5758fd68e73303726f65f96f1 to your computer and use it in GitHub Desktop.
Verifies that any change value under 1 dollar can be created with 3 quarters, 1 dime, 2 nickels, and 4 pennies
def coins_can_make_value(coin_dictionary: dict[int, int], value: float) -> bool:
if value == 0:
return True
for coin_value, coin_count in coin_dictionary.items():
for _ in range(coin_count):
if value >= coin_value:
value -= coin_value
if value == 0:
return True
return False
def main() -> None:
coin_dictionary: dict[int, int] = {
25: 3,
10: 1,
5: 2,
1: 4,
}
can_make_every_change_combo: bool = True
for value in range(100):
change_combo_can_be_made: bool = coins_can_make_value(coin_dictionary, value)
if not change_combo_can_be_made:
can_make_every_change_combo = False
print(f"{value}: {change_combo_can_be_made}")
outcome = "Success" if can_make_every_change_combo else "Failure"
print(outcome)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment