Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def jumpIt(n, k, lst):
- sums = []
- #sums will collect the 'cost' of the game in a list
- if (k > n-1):
- #first base case if the list if the length is 0
- return 0
- elif (k+1 > n-1):
- #2nd base case if the list is two cells
- return lst[k]
- else:
- if (lst[k] < lst[k+1]):
- sums.append(lst[k])
- #if the cell of K is less than k+1 computes:
- return lst[k] + jumpIt(n, k+2, lst)
- else:
- sums.append(lst[k+1])
- return lst[k+1] + jumpIt(n, k+2, lst)
- def main():
- #list to sum the cost of each move
- fileName = "input.txt"
- for line in open(fileName):
- lst = line.split()
- lst = [int(x) for x in lst]
- print(jumpIt(len(lst),1,lst))
- main()
- 19
- 87
- 138
- 186
- 330
- 19
- 85
- 108
- 157
- 224
Add Comment
Please, Sign In to add comment