Thanks for the explanation! Although this solution works well it's a bit more complex than necessary. What about using cosine and sine? ``` x = 0 y = 0 rotation = 0 for instruction in instructions: if instruction == "L": rotation += 270 rotation = rotation % 360 elif instruction == "R": rotation += 90 rotation = rotation % 360 else: y -= int(math.cos(math.radians(rotation))) x += int(math.sin(math.radians(rotation))) if x == 0 and y == 0: return True elif rotation != 0: return True return False ``` Or without these functions the movement can be done like this: ``` if rotation % 180 == 0: y += (rotation / 90) - 1 else: x -= (rotation / 90) - 2 ```
thank you so much! very clear and easy solution!
Thanks for the explanation! Although this solution works well it's a bit more complex than necessary. What about using cosine and sine?
```
x = 0
y = 0
rotation = 0
for instruction in instructions:
if instruction == "L":
rotation += 270
rotation = rotation % 360
elif instruction == "R":
rotation += 90
rotation = rotation % 360
else:
y -= int(math.cos(math.radians(rotation)))
x += int(math.sin(math.radians(rotation)))
if x == 0 and y == 0:
return True
elif rotation != 0:
return True
return False
```
Or without these functions the movement can be done like this:
```
if rotation % 180 == 0:
y += (rotation / 90) - 1
else:
x -= (rotation / 90) - 2
```