Roll the Alphabet into a Spiral


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=POWER(@z-1,.5)+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(a-x>=b-y and x-a<y-b,-2,IIF(a=x and b=y or a<x and b-y<=x-a,1,2)))z)x WHERE i<@z-1)SELECT @o=STUFF(@o,@*a-@+b,1,char(i%26+65))FROM c OPTION(maxrecursion 0)PRINT @o

Enter Parameters

Switch sites:
loading Hold tight while we fetch your results