
参考:https://blog.csdn.net/yhmhappy2006/article/details/2934435
function main()local t = {} --可视化螺旋阵列local t1={} --转换成螺旋坐标local y1=0for y = -5,5 doy1=y1+1t[y1]={}local x1=0for x = -5,5 dox1=x1+1t[y1][x1]=spiral(x, y)t1[spiral(x, y)]={x1,y1}endendprint(t) --必须使用支持打印表的函数print(t1)endfunction spiral(x,y)local c = max(math.abs(x), math.abs(y)) --当前坐标所在圈local max1 = (c * 2 + 1) * (c * 2 + 1) --当前圈上最大值if y == -c then --上边return max1 + (x + y)elseif (x == -c) then --左边return max1 + (3 * x - y)elseif (y == c) then --下return max1 + (-x - 5 * y)else --右边return max1 + (-7 * x + y)endendfunction max(n1,n2)if n1 > n2 thenreturn n1elsereturn n2endendmain()--[[{{111,112,113,114,115,116,117,118,119,120,121,},{110, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,},{109, 72, 43, 44, 45, 46, 47, 48, 49, 50, 83,},{108, 71, 42, 21, 22, 23, 24, 25, 26, 51, 84,},{107, 70, 41, 20, 7, 8, 9, 10, 27, 52, 85,},{106, 69, 40, 19, 6, 1, 2, 11, 28, 53, 86,},{105, 68, 39, 18, 5, 4, 3, 12, 29, 54, 87,},{104, 67, 38, 17, 16, 15, 14, 13, 30, 55, 88,},{103, 66, 37, 36, 35, 34, 33, 32, 31, 56, 89,},{102, 65, 64, 63, 62, 61, 60, 59, 58, 57, 90,},{101,100, 99, 98, 97, 96, 95, 94, 93, 92, 91,},}]]
