# 삼각 달팽이 - 프로그래머스
def solution(n):
li = [[0] * n for _ in range(n)]
ret = []
x, y = -1, 0
num = 1
for i in range(n):
for j in range(i, n):
if i % 3 == 0: # 첫째 줄
x += 1
elif i % 3 == 1: # 둘째 줄
y += 1
elif i % 3 == 2: # 셋째 줄
x -= 1
y -= 1
li[x][y] = num
num += 1
for i in li:
for j in i:
if j != 0:
ret.append(j)
return ret