Created
September 24, 2012 17:15
-
-
Save truncs/3777093 to your computer and use it in GitHub Desktop.
coin change
This file contains 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
#! /usr/bin/python | |
import sys | |
denominations = [1, 2,3] | |
def find_all_denom(value, denom, current_denom): | |
if value < 0: | |
return | |
if value == 0: | |
print current_denom | |
for de in denom: | |
find_all_denom(value - de, denominations,current_denom + str(de) ) | |
d = {} | |
def find_optimal_solution(value, denom): | |
if value in denom: | |
return 1 | |
if value < 0: | |
return sys.maxint; | |
else: | |
for d in denom: | |
change = [] | |
change.append(find_optimal_solution(value - d, denom)) | |
return 1 + min(change) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment