Guest User

Untitled

a guest
Feb 13th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. def jumpIt(n, k, lst):
  2. sums = []
  3. #sums will collect the 'cost' of the game in a list
  4. if (k > n-1):
  5. #first base case if the list if the length is 0
  6. return 0
  7. elif (k+1 > n-1):
  8. #2nd base case if the list is two cells
  9. return lst[k]
  10. else:
  11. if (lst[k] < lst[k+1]):
  12. sums.append(lst[k])
  13. #if the cell of K is less than k+1 computes:
  14. return lst[k] + jumpIt(n, k+2, lst)
  15. else:
  16. sums.append(lst[k+1])
  17. return lst[k+1] + jumpIt(n, k+2, lst)
  18.  
  19.  
  20.  
  21. def main():
  22. #list to sum the cost of each move
  23. fileName = "input.txt"
  24. for line in open(fileName):
  25. lst = line.split()
  26. lst = [int(x) for x in lst]
  27. print(jumpIt(len(lst),1,lst))
  28.  
  29. main()
  30.  
  31. 19
  32. 87
  33. 138
  34. 186
  35. 330
  36.  
  37. 19
  38. 85
  39. 108
  40. 157
  41. 224
Add Comment
Please, Sign In to add comment