Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Problem 31
- #findIndex(num(str), lst(list)) -> num(str)
- #get rest value(num) and current list(list),
- #returning the highest possible value which
- #is less than num
- def findIndex(num, lst):
- if num == 0:
- raise "findIndex num == 0"
- while True:
- if num in lst:
- return lst[lst.index(num)]
- elif num == 0:
- return None
- num -= 1
- lst = [200, 100, 50, 20, 10, 5, 2, 1]
- tmp = lst[:]
- combi = 0
- rest = 200
- isRunning = True
- while isRunning:
- #If all combinations found
- if len(tmp) == 0:
- isRunning = False
- #If found new combination
- if rest == max(tmp):
- combi += 1
- rest = 200
- #- #If no more combinations with max value, then:
- #lst = lst[1:]
- tmp = lst[:]
- #If rest is more than max value
- if rest > max(tmp):
- rest -= max(tmp)
- #If rest is less than max value
- elif rest < max(tmp):
- value = findIndex(rest, tmp)
- #If highest possible value can be added
- #This test is not really important
- if rest:
- if rest - value >= 0:
- rest -= value
- else:
- raise "no match in findIndex"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement