This is the sequence:
JavaScript
x
2
1
1, 2, 3, -1, 7, -10, 3, -73, …
2
and actually it’s like this:
JavaScript
1
2
1
t(n) = (t(n-3) * t(n-2)) - t(n-1)
2
for example: -10 = (3 * -1) - 7
.
I used this code but it’s not acting like this equation that I have provided.
JavaScript
1
15
15
1
n1 = 1
2
n2 = 2
3
n3 = 3
4
m = eval(input("number: "))
5
if m < 4:
6
if m == n1:
7
print(n1)
8
elif m == n2:
9
print(n2)
10
elif m == n3:
11
print(n3)
12
elif m >= 4:
13
n4 = (n1 * n2 - n3)
14
print(n4)
15
Advertisement
Answer
This is my solution to finding t(m)
JavaScript
1
6
1
n = [1,2,3]
2
m = int(input("number: ")) #eval is a big security risk!!!
3
while len(n) < m:
4
n.append((n[-3] * n[-2] - n[-1]))
5
print(n[m-1])
6
where n[negative number] is a number from the end of the list.
Results in:
JavaScript
1
2
1
1, 2, 3, -1, 7, -10, 3, -73, 43, -262, -2877, -8389, 762163, 23372990, etc.
2