Created
August 22, 2014 03:26
-
-
Save yuheiomori/7f9c42291424f05236ef to your computer and use it in GitHub Desktop.
Minimum Coins (CodeEval) in python 3.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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