Skip to content

Commit 584277f

Browse files
authored
Update solution.hide.py
1 parent 762b3e9 commit 584277f

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed
Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
# Your code here
2-
import math
2+
def compute_robot_distance(movements):
3+
x, y = 0, 0
34

4-
def compute_robot_distance(props):
5-
pos = [0,0]
6-
new_prop = props.split(" ")
7-
for x in range(len(new_prop)):
8-
if new_prop[x].upper() == 'UP':
9-
pos[0]+=int(new_prop[x+1])
10-
elif new_prop[x].upper() == 'DOWN':
11-
pos[0]-=int(new_prop[x+1])
12-
elif new_prop[x].upper() == 'LEFT':
13-
pos[1]-=int(new_prop[x+1])
14-
elif new_prop[x].upper() == 'RIGHT':
15-
pos[1]+=int(new_prop[x+1])
16-
else:
17-
None
18-
return (int(round(math.sqrt(pos[1]**2+pos[0]**2))))
5+
for move in movements:
6+
direction, steps = move.split()
7+
steps = int(steps)
198

20-
print(compute_robot_distance("UP 5 DOWN 3 LEFT 3 RIGHT 2"))
9+
if direction == "UP":
10+
y += steps
11+
elif direction == "DOWN":
12+
y -= steps
13+
elif direction == "LEFT":
14+
x -= steps
15+
elif direction == "RIGHT":
16+
x += steps
17+
18+
distance = (x**2 + y**2)**0.5
19+
rounded_distance = round(distance)
20+
21+
return rounded_distance
22+
23+
print(compute_robot_distance(["UP 5", "DOWN 3", "LEFT 3", "RIGHT 2"]))

0 commit comments

Comments
 (0)