삼각달팽이
def solution(n):
a = [[0] * i for i in range(1, n + 1)]
x, y = 0, 0; d = 0
dx = [1, 0, -1]
dy = [0, 1, -1]
k = (n * (n + 1)) // 2
num = 1
while num < k:
a[x][y] = num
nx = x + dx[d]
ny = y + dy[d]
if 0 > nx or n <= nx or (nx - ny) < 0 or a[nx][ny] != 0:
d = (d + 1) % 3
nx = x + dx[d]
ny = y + dy[d]
x, y = nx, ny
num += 1
s = []
for v in a:
s.extend(v)
return sLast updated