Roll the Alphabet into a Spiral

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

DECLARE @z INT = 7744

DECLARE @ INT=SQRT(@z-1)+2DECLARE @o varchar(max)=REPLICATE(SPACE(@-1)+char(10),@-1);WITH C as(SELECT @/2x,@/2y,0i,@/2a,@/2b UNION ALL SELECT x,y,i+1,a+z/2,b+z%2FROM C CROSS APPLY(SELECT IIF(a-x>=b-y and x-a<b-y,-1,IIF(x-a<y-b,-2,IIF(b-y>x-a,2,1)))z)t WHERE i<@z-1)SELECT @o=STUFF(@o,@*a-@+b,1,char(i%26+65))FROM c OPTION(maxrecursion 0)PRINT @o

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results