Back
Close

Turtle

Statement

 Goal

A turtle moves on a board by following a sequence of simple instructions :
LEFT to turn left
RIGHT to turn right
or an integer d indicating the distance to be covered (note that d can be negative when the turtle has to move backwards)

The turtle is initially aligned on the horizontal axis looking to the right.
Input
Line 1: 2 integers x and y for the coordinates of the starting point
Line 2: An integer n for the number of instructions given to the turtle
n next lines: cmd containing either a LEFT or RIGHT instruction or a distance to travel
Output
A line containing x and y the new coordinates of the turtle.
Constraints
0<n<100
-100<=x,y,distance<=100
Example
Input
50 50
3
10
RIGHT
10
Output
60 40

Game modes
Fastest

Test cases
Right turn Test
Input
50 50 3 10 RIGHT 10
Output
60 40

Validator 1 Validator
Input
10 10 3 20 RIGHT 5
Output
30 5

Reverse Test
Input
0 0 2 10 -30
Output
-20 0

Validator 2 Validator
Input
10 10 2 5 -20
Output
-5 10

Slalom Test
Input
0 0 9 10 RIGHT 10 LEFT 10 RIGHT 10 LEFT 10
Output
30 -20

Validator 3 Validator
Input
50 50 9 10 RIGHT 10 LEFT 10 RIGHT 10 LEFT 10
Output
80 30

Loop Test
Input
0 0 8 10 LEFT 10 LEFT 10 LEFT 10 LEFT
Output
0 0

Validator 4 Validator
Input
10 10 8 20 RIGHT 20 RIGHT 20 RIGHT 20 RIGHT
Output
10 10

Let's go for a walk Test
Input
0 0 13 8 LEFT 30 LEFT -10 LEFT 61 RIGHT 39 -6 LEFT LEFT 12
Output
-3 -31

Validator 5 Validator
Input
0 0 13 12 RIGHT 9 LEFT -5 LEFT 41 RIGHT 39 -6 LEFT LEFT 12
Output
28 32

Solution language

Solution

Stub generator input