Skip to content

Instantly share code, notes, and snippets.

@yuheiomori
Created August 22, 2014 03:26
Show Gist options
  • Save yuheiomori/7f9c42291424f05236ef to your computer and use it in GitHub Desktop.
Save yuheiomori/7f9c42291424f05236ef to your computer and use it in GitHub Desktop.
Minimum Coins (CodeEval) in python 3.x
# coding=utf-8
import sys
coin_values = [1, 3, 5]
def main():
with open(sys.argv[1], "r") as f:
for line in f:
line = line.rstrip()
value = int(line)
total_coin_count = 0
for coin_value in reversed(coin_values):
coin_count = value // coin_value
total_coin_count += coin_count
value -= coin_count * coin_value
if value == 0:
break
print(total_coin_count)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment