Coding Challenge: Online IDE
Coding Challenge: Online IDE
dev/ or
any other.
Coding Challenge
The Robo Treasure Hunt
Company Rubix has a 6X6 Robot play arena with treasures hidden at certain locations (think
of it as a 6X6 grid). There are 2 players - Robo1 and Robo2.
Each player can command and control their robots. There are treasures laid out on different
points in the arena and the robot needs to collect treasures on the route we define.
Your coding challenge is to display the player who has more treasures.
For example 2 3 N means the Robot is at 2 on the x coordinate, 3 on the y coordinate, and
facing North.
You can control the robot by sending 'L', 'R' and 'M'. 'L' and 'R' makes the robot turn 90
degrees left or right respectively, without moving from its current spot. 'M' means moving
forward one grid point in the direction it is facing.
The 1st line of input has comma separated coordinates of the treasure locations.
Eg: if the input is 1 3, 3 3 it means treasures are available at grid locations 1 3 and 3 3.
The next 2 lines of input is the information pertaining to the robots that have been deployed.
Each of these lines gives the robot's position, and a series of instructions telling the robot
how to navigate the grid.
The output should print the name of the players, and their final position, with their treasure
count. Also indicate who won the treasure hunt.
Sample Input1 -
1 1, 3 3, 5 5
Robo1 0 2 E MMMLM
Robo2 5 0 N MMMMM
Output
Robo1 3 3 N 1
Robo2 5 5 N 1
TIE
Sample Input2 -
4 5, 2 3, 4 1, 4 4, 5 2
Robo1 1 2 N MRMMLMMMRMRMM
Robo2 2 0 S LMMLMMRMLMMMML
Output
Robo1 4 3 S 3
Robo2 5 5 W 2
Robo1 WINS
Upload code here when done -> https://codu.ai/upload/Rubix. Do mention your full name
and correct email id when you submit. Choose Robo Hunt as the coding problem.
Assumptions:
• If the Robot reaches the boundary and if he will fall off the grid on the next
instruction, then skip that instruction and move on to next. Each treasure location has
an unlimited amount of treasures. At a time a Robot can pick only one treasure from
one spot. A tie is a possible outcome.
• If 2 robots are in the same grid, both of them get a treasure.
6 x 6 matrix
5, 0 5, 1 5, 2 5, 3 5, 4 5, 5
4, 0 4, 1 4, 2 4, 3 4, 4 4, 5
3, 0 3, 1 3, 2 3, 3 3, 4 3, 5
2, 0 2, 1 2, 2 2, 3 2, 4 2, 5
1, 0 1, 1 1, 2 1, 3 1, 4 1, 5
0, 0 0, 1 0, 2 0, 3 0, 4 0, 5