fork download
  1. def recursive_transform(lst, index=0):
  2. if index >= len(lst):
  3. return
  4. if lst[index] % 2 == 0:
  5. lst[index] //= 2
  6. else:
  7. lst[index] = lst[index] * 3 + 1
  8. recursive_transform(lst, index + 1)
  9. if index < len(lst) - 1:
  10. lst[index] += lst[index + 1]
  11.  
  12. numbers = [5, 8, 3, 7, 10]
  13. recursive_transform(numbers)
  14.  
  15. for i in range(len(numbers) - 1, -1, -1):
  16. numbers[i] = numbers[i] - (numbers[i - 1] if i > 0 else 0)
  17.  
  18. print(numbers)
  19.  
Success #stdin #stdout 0.03s 9652KB
stdin
Standard input is empty
stdout
[57, -16, -4, -10, -22]