I made my own sequence recently (called the Piggyback sequence), and it works like this:
P(1)
, P(2)
and P(3)
= 1
.
For all P(n)
where n>3
, the sequence works like this:
P(n) = P(n-3) + P(n-2)/P(n-1)
So, continuing the sequence:
P(4)
= 1 + 1/1
= 2
P(5)
= 1 + 1/2
= 3/2
= 1.5
P(6)
= 1 + 2/(3/2)
= 7/3
= 2.33333...
P(7)
= 2 + (3/2)/(7/3)
= 37/14
= 2.6428571428...
P(8)
= 3/2 + (7/3)/(37/14)
= 529/222
= 2.3828828828...
Your task is, when given n
, calculate P(n)
either as a floating point number or an (im)proper fraction.
This is code-golf, so shortest code in bytes wins.
If anyone can find the name of the sequence, please edit the post accordingly.
P(0)=1
... \$\endgroup\$