Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- def jumps(elements):
- current = elements[0]
- remaining = len(elements)
- if current == 0: # base case: can't jump from 0
- return sys.maxint
- elif remaining == 1: # base case: reached end
- return 0
- else: # recursive case
- js = range(1, min(current+1, remaining))
- candidates = map(lambda j: jumps(elements[j:]), js)
- return 1 + min(candidates)
- print jumps([0]) == sys.maxint
- print jumps([9]) == 0
- print jumps([1,3,5,8,9,2,6,7,6,8,9]) == 3
- print jumps([1,3,5,0,1,9,1,1,1,1,1,1,1]) == 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement