Quantcast
Channel: Spiral Permutation Sequence - Code Golf Stack Exchange
Browsing latest articles
Browse All 10 View Live

Answer by Razetime for Spiral Permutation Sequence

APL (Dyalog Extended), 2519 14 bytes{2⊥⍨3⍴⌊√⍵-1}-⊢-6 bytes from Adám.-5 bytes from Bubbler.Try it online!A direct implementation of the last function mentioned on the OEIS...

View Article



Answer by Fatalize for Spiral Permutation Sequence

Brachylog, 20 bytes-1$r$[I*I+I+1=*2-?=.This uses the same technique as pretty much all other answers.Explanation-1 § Build the expression Input - 1 $r § Square root of Input - 1 $[I § Unify I with the...

View Article

Answer by Neil for Spiral Permutation Sequence

ES7, 3128 26 bytesn=>(m=--n**.5|0)*++m*2-~-nI had independently discovered Alex's formula but I can't prove it because I wasn't near a computer at the time.Edit: Saved 3 bytes partly thanks to...

View Article

Answer by Luis Mendo for Spiral Permutation Sequence

MATL, 16 13 bytesqX^Y[tQ*Q2*G-Based on Lynn's CJam answer.Try it online! (Y[ has been replaced by k according to changes in the language)q % input n. Subtract 1X^ % square rootY[ % floortQ % duplicate...

View Article

Answer by Alex A. for Spiral Permutation Sequence

Julia, 28 bytesn->2((m=isqrt(n-1))^2+m+1)-nThis 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...

View Article


Answer by Denker for Spiral Permutation Sequence

Pyth, 21 bytesK2-h+^.E@QKK^t.E@QKKQTry it online!Nothing fancy going on. Same method as in the JAPT answer.

View Article

Answer by lirtosiast for Spiral Permutation Sequence

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,...

View Article

Answer by Lynn for Spiral Permutation Sequence

CJam, 14 bytesqi_(mQ7Ybb2*\-Using Alex's approach: 2*(m^2+m+1)-n where m = isqrt(n-1).

View Article


Answer by ETHproductions for Spiral Permutation Sequence

Japt, 2019 16 bytesV=U¬c)²-V *2-U+2Test it online!Based on the observation thatOr, rather, thatI don't know if this explanation is on the OEIS page, as I haven't looked at it yet.

View Article


Spiral Permutation Sequence

We can roll up the natural numbers in a rectangular spiral: 17--16--15--14--13 | | 18 5---4---3 12 | | | | 19 6 1---2 11 | | | 20 7---8---9--10 | 21--22--23--24--25But now that we have them on a...

View Article
Browsing latest articles
Browse All 10 View Live




Latest Images