Link : programmers.co.kr/learn/courses/30/lessons/68645
Programming Language
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
def solution(n):
answer = [[0 for _ in range(n)] for _ in range(n)]
dir_value = 0
counting = 1
pos = [0, 0] # x, y
for i in range(n, 0, -1):
for j in range(i):
if dir_value % 3 == 0: # down
answer[pos[1]][pos[0]] = counting
pos[1] += 1
elif dir_value % 3 == 1: # right
answer[pos[1]][pos[0]] = counting
pos[0] += 1
elif dir_value % 3 == 2: # up left
answer[pos[1]][pos[0]] = counting
pos[0] -= 1
pos[1] -= 1
counting += 1
if dir_value % 3 == 0:
pos[1] -= 1
pos[0] += 1
elif dir_value % 3 == 1:
pos[1] -= 1
pos[0] -= 2
elif dir_value % 3 == 2:
pos[0] += 1
pos[1] += 2
dir_value += 1
result = []
for i in answer:
for j in i:
if j != 0:
result.append(j)
return result
|
cs |
FeedBack
cjw.git@gmail.com
'알고리즘 > 소스코드' 카테고리의 다른 글
PROGRAMMERS 42587: 프린터 (0) | 2021.01.09 |
---|---|
PROGRAMMERS 12953: N개의 최소공배수 (0) | 2021.01.06 |
PROGRAMMERS 49993: 스킬트리 (0) | 2021.01.06 |
PROGRAMMERS 43162: 네트워크 (0) | 2021.01.06 |
PROGRAMMERS 42860: 조이스틱 (0) | 2021.01.06 |
댓글