Skip to content

Commit 9787234

Browse files
authored
[Miller] PROGRAMMERS(86052): 빛의 경로 사이클 - 문제풀이 추가 (#164)
1 parent 2a88983 commit 9787234

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/밀러/PROGRAMMERS_86052.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from typing import List
2+
3+
4+
def solution(grid: List[str]) -> List[int]:
5+
row: int = len(grid)
6+
col: int = len(grid[0])
7+
8+
space: List[List[List[bool]]] = [[[False for _ in range(4)]
9+
for _ in range(col)] for _ in range(row)]
10+
11+
dr = [-1, 0, 1, 0] # [north, east, south, west]
12+
dc = [0, 1, 0, -1]
13+
14+
result: List[int] = []
15+
for i in range(len(space)):
16+
for j in range(len(space[0])):
17+
for k in range(4):
18+
if space[i][j][k]:
19+
continue
20+
21+
r, c, d = i, j, k
22+
count: int = 0
23+
while True:
24+
if grid[r][c] == "S":
25+
r = (r + dr[(d + 0) % 4]) % row
26+
c = (c + dc[(d + 0) % 4]) % col
27+
elif grid[r][c] == "L":
28+
r = (r + dr[(d + 1) % 4]) % row
29+
c = (c + dc[(d + 1) % 4]) % col
30+
d = (d + 1) % 4
31+
else:
32+
r = (r + dr[(d - 1) % 4]) % row
33+
c = (c + dc[(d - 1) % 4]) % col
34+
d = (d - 1) % 4
35+
36+
if space[r][c][d]:
37+
break
38+
39+
space[r][c][d] = True
40+
count += 1
41+
42+
result.append(count)
43+
44+
return sorted(result)
45+
46+
47+
if __name__ == "__main__":
48+
print(solution(["SL", "LR"]))
49+
print(solution(["S"]))
50+
print(solution(["R", "R"]))

0 commit comments

Comments
 (0)