Unexpected Behaviour In This Program In Python
I have this code to calculate minimum number of coins from a sum with given list of denomiations. for eg : minimum change for 69 with denomiations [25,10,5,1] : [25, 25, 10, 5,
Solution 1:
if __name__ == "__main__":
cache_denom_set1 = {}
cache_denom_set2 = {}
print"minimum change for 69 with denomiations [25,10,5,1] by recursive : ",get_min_coin_configuration(69,[25,10,5,1],cache_denom_set1)
print"*"*45
print"minimum change for 7 with denomiations [4,3,1] by recursive : ",get_min_coin_configuration(7,[4,3,1],cache_denom_set2)
pass in a separate cache for each set of denominations
the problem is that your cache already knows how to make change for 7 as 5,1,1 so it just returns that ... the cache is unaware that 5 is no longer in the denomination set ...
dictionaries are mutable like lists ... this should demonstrate the problem
defdict_fn(cache={}):
cache[len(cache.keys())] = 1print cache
dict_fn()
dict_fn()
Post a Comment for "Unexpected Behaviour In This Program In Python"