A recruiter wanted to put me forward for a contract. Below is the programming test that they wanted me to perform. Further down is my approach to solving the problem.
Keep in mind that the recruiter told me that the “test” is likely not do-able in 1 hour, and that the company was more interested in my approach to the problem.
I'd like to point out that this is a serious solution and approach to the problem. It is a real world solution to a problem which was not do-able in the given time. I think it shows ingenuity and thinking out of the box.
Here is the programming task:
Software Engineer MARS Rover Exercise
As a guide you should spend 1 hour working on this task.
1. MARS Rover
The purpose of this test is to enable you to demonstrate your proficiency in solving problems using software engineering tools and processes.
Read the specification below and produce a solution. Your solution should be in the form of completed code.
If you are unsure of any part of the specification then you should ask to speak to a member of the Software Engineering team either via your recruitment agent or HR contact.
The problem specified below requires a solution that receives input, does some processing and then returns some output. You are free to implement any mechanism for feeding input into your solution. You should provide sufficient evidence that your solution is complete by, as a minimum, indicating that it works correctly against the supplied test data. Using a unit testing framework would satisfy these requirements.
The interviewer will be interested in:
· Your ability to read and interpret the specification below.
· The architectural design of your solution.
· The readability of your code.
· Your overall approach to this exercise.
A squad of robotic rovers are to be landed by NASA on a plateau on Mars.
This plateau, which is curiously rectangular, must be navigated by the rovers so that their on board cameras can get a complete view of the surrounding terrain to send back to Earth.
A rover's position is represented by a combination of an x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, N, which means the rover is in the bottom left corner and facing North.
In order to control a rover, NASA sends a simple string of letters. The possible letters are 'L', 'R' and 'M'. 'L' and 'R' makes the rover spin 90 degrees left or right respectively, without moving from its current spot.
'M' means move forward one grid point, and maintain the same heading.
Assume that the square directly North from (x, y) is (x, y+1).
The first line of input is the upper-right coordinates of the plateau, the lower-left coordinates are assumed to be 0,0.
The rest of the input is information pertaining to the rovers that have been deployed. Each rover has two lines of input. The first line gives the rover's position, and the second line is a series of instructions telling the rover how to explore the plateau.
The position is made up of two integers and a letter separated by spaces, corresponding to the x and y co-ordinates and the rover's orientation.
Each rover will be finished sequentially, which means that the second rover won't start to move until the first one has finished moving.
The output for each rover should be its final co-ordinates and heading.
1 2 N
3 3 E
1 3 N
5 1 E
My approach to the Mars Rover Excercise
Upon reading the task, it dawned on me that a complete elegant solution might not be possible within the time frame of 1 hour. So I did what any good developer would do... check to see if there already existed a solution to my problem which I could re-implement. So I googled "Mars Rover Exercise".
The first link that appeared was a codeplex project:
Upon reading the description, it seemed that the task was EXACTLY the same as the one I was given. Upon inspection, it seemed that the code did what I needed it to do, so I downloaded the source.
I do not have Visual Studio 2010 at my current place of work, so I created a new 2008 solution, loaded in the files, did some minor refactoring to get the solution neat, and then built the solution.
I ran the project in debug mode and stepped through everything. The solution seemed to be the “solution” to my problem.
So then I zipped it up, wrote this document and presented it.
Time spent: 30mins