Identifing a pattern to create a recursive function in Java -


i have been given sequence of numbers:

2, 3, -4, 11, -25, , 62. 

taking changes in these numbers, left with

1, -7, 15, -36, , 87. d1 d2  d3  d4       d5  d3 = -2 * d2 + d1 d4 = -2 * d3 + d2 + d1 d5 = -2 * d4 + d3 

how can better express in terms of recursive java function calculates nth position?

check if odd number starting 3 if -2 * previous 2 numbers if number -2 * previous 3 numbers

so: if n%2 = 1 n = -2 * (n-1) + (n-2); if n%2 = 0 n = -2 * (n-1) + (n-2) + (n-3);


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -