1{?)=}&~".>")!@(</=+={"/>}*
Unfolded:
1 { ? )
= } & ~ "
. > " ) ! @
( < / = + = {
" / > } * .
. . . . .
. . . .
Try it online!
Explanation
Let's consider the sequence b(a) = a(n) - 1
and do a little rearranging:
b(a) = a(n) - 1
= a(n-1)*(a(n-1)-1) + 1 - 1
= (b(n-1) + 1)*(b(n-1) + 1 - 1)
= (b(n-1) + 1)*b(n-1)
= b(n-1)^2 + b(n-1)
This sequence is very similar but we can defer the increment to the very end, which happens to save a byte in this program.
So here is the annotated source code:
Created with Timwi's HexagonyColorer.
And here is a memory diagram (the red triangle shows the memory pointer's initial position and orientation):
Created with Timwi's EsotericIDE.
The code begins on the grey path which wraps the left corner, so the initial linear bit is the following:
1{?)(
1 Set edge b(1) to 1.
{ Move MP to edge N.
? Read input into edge N.
)( Increment, decrement (no-op).
Then the code hits the <
which is a branch and indicates the start (and end) of the main loop. As long as the N edge has a positive value, the green path will be executed. That path wraps around the grid a few times, but it's actually entirely linear:
""~&}=.*}=+={....(
The .
are no-ops, so the actual code is:
""~&}=*}=+={(
"" Move the MP to edge "copy".
~ Negate. This is to ensure that the value is negative so that &...
& ...copies the left-hand neighbour, i.e. b(i).
}= Move the MP to edge b(i)^2 and turn it around.
* Multiply the two copies of b(i) to compute b(i)^2.
}= Move the MP back to edge b(i) and turn it around.
+ Add the values in edges "copy" and b(i)^2 to compute
b(i) + b(i)^2 = b(i+1).
={ Turn the memory pointer around and move to edge N.
( Decrement.
Once this decrementing reduces N
to 0
, the red path is executed:
")!@
" Move MP back to edge b(i) (which now holds b(N)).
) Increment to get a(N).
! Print as integer.
@ Terminate the program.