Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions heeheej/week30/PRG_121687_실습용로봇.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# PCCP 모의고사 2 1번 실습용로봇

def solution(command):
answer = []
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
nx, ny = 0, 0
d = 0 # 방향인덱스

def rotateRight90(d):
return (d + 1) % 4

for x in command:
if x == "G":
nx += dx[d]
ny += dy[d]
elif x == "B":
nx -= dx[d]
ny -= dy[d]
elif x == "R":
d = (d + 1) % 4
elif x == "L":
d -= 1
if d < 0:
d = 3
answer = [nx, ny]
return answer