Spiral Permutation Sequence

Japt, 20 19 16 bytes

V=U¬c)²-V *2-U+2

Test it online!

Based on the observation that

F(N) = ceil(N^.5) * (ceil(N^.5)-1) - N + 2

Or, rather, that

F(N) = the first square greater than or equal to N, minus its square root, minus N, plus 2.

I don't know if this explanation is on the OEIS page, as I haven't looked at it yet.


Jelly, 11 10 bytes

’ƽð²+ḷ‘Ḥ_

Another Jelly answer on my phone.

’ƽð²+ḷ‘Ḥ_   A monadic hook:
’ƽ          Helper link. Input: n
’             n-1
 ƽ            Atop integer square root. Call this m.
   ð         Start a new dyadic link. Inputs: m, n
    ²+ḷ‘Ḥ_    Main link:
    ²+ḷ       Square m, add it to itself,
       ‘      and add one.
        Ḥ     Double the result
         _    and subtract n.

Try it here.


Julia, 28 bytes

n->2((m=isqrt(n-1))^2+m+1)-n

This is a lambda function that accepts an integer and returns an integer. To call it, assign it to a variable.

We define m to be the largest integer such that m2n-1, i.e. the integer square root of n-1 (isqrt). We can then simplify the OEIS expression 2 (m + 1) m - n + 2 down to simply 2 (m2 + m + 1) - n.

Try it online