One Project, Six or Seven, Maybe Eight Languages…

The Project: Mars Rover Technical Challenge

The problem below requires some kind of input. You are free to implement any mechanism for feeding input into your solution (for example, using hard coded data within a unit test). You should provide sufficient evidence that your solution is complete by, as a minimum, indicating that it works correctly against the supplied test data.

We highly recommend using a unit testing framework such as JUnit or NUnit. Even if you have not used it before, it is simple to learn and incredibly useful.

The code you write should be of production quality, and most importantly, it should be code you are proud of.

MARS ROVERS

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).

Input:

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.

Output:

The output for each rover should be its final co-ordinates and heading.

Test Input:

5 5

1 2 N

LMLMLMLMM

3 3 E

MMRMMRMRRM

Expected Output:

1 3 N

5 1 E

The Code

AS3 and Flash Builder 4

The Mars Rover Technical Challenge was prototyped using AS3 and Flash Builder 4 as a way to visualize the problem.
(See “MarsRoverSample (AS3).zip“).

Ruby on Rails 2.3.8 for Ruby 1.8.7

Then the Mars Rover Technical Challenge was recoded using Ruby on Rails 2.3.8 using the algorithms that were
developed during the AS3 prototype effort; one minor bug was fixed from the AS3 code however the original AS3 code
was left untouched for comparison.  The toolchain used for this was Ruby 1.8.7 with Rails 2.3.8 and Aptana 2.0;
NetBeans 6.8 proved to be to much of a hassle to use it.  Notice the command that runs some hand-coded Unit Tests,
“ruby script/tests”; this was done to demonstrate how Ruby can be used to code Unit Tests.
(See “MarsRoverSample2 (RoR 2.3.8+jQuery).zip“).

JavaScript and jQuery

Then the Mars Rover Technical Challenge was recoded using JavaScript and jQuery and aligned with the Rails 2.3.8
effort to allow both to coexist on the same web page for comparison purposes. The toolchain used for this was
Ruby 1.8.7 with Rails 2.3.8 and Aptana 2.0 along with the latest jQuery and some JavaScript code I had sitting on
my shelf from 2003.
(See “MarsRoverSample2 (RoR 2.3.8+jQuery).zip“).

Python 2.5.5.7

Then the Mars Rover Technical Challenge was recoded using Python 2.5.5.7 as a command line demo.  The toolchain for this
was the Wing IDE 3.2 and Python 2.5.5.7.  The JavaScript version was ported to Python by making changes as applicable
to make the JavaScript code into Python code.
(See “marsRoverSample (Python 2.5.5.7).zip“).

Stackless Python 2.5.2

Then the Mars Rover Technical Challenge was recoded using Stackless Python 2.5.2 using the original Python 2.5.5.7 code
without modification.  The toolchain for this was the Wing IDE 3.2 and Stackless Python 2.5.2.
(See “marsRoverSample (Stackless Python 2.5.2).zip“).

PHP 5.3.2 using the Zend Community Server 5.0.1

Then the Mars Rover Technical Challenge was recoded using PHP 5.3.2 using the Zend Community Server 5.0.1
and Zend Studio 7.2.0.  The Ruby on Rails code was ported to PHP by porting over the HTML portions then the JavaScript
version was translated to PHP code.
(See “MarsRoverSample2 (PHP 5.3.2+jQuery).zip“).

Lua 5.1.4 using the Lua for Windows

Then the Mars Rover Technical Challenge was recoded using Lua 5.1.4 using the Lua for Windows toolchain by porting
the JavaScript version to Lua.
(See “MarsRoverSample (Lua 5.1.4).zip“).

C# 2008 using Visual Studio 2008

Then the Mars Rover Technical Challenge was recoded using C# 2008 using the Visual Studio 2008 toolchain by porting
the JavaScript version to C#.  A complete set of Unit Tests were coded as in-line C# code.
(See “MarsRoverSample (VS2008 C#).zip“).

Some information

You will notice from the code samples the Ruby on Rails 2.3.8 and PHP 5.3.2 versions are both integrated with the JavaScript/jQuery version with both the client-side and the server-side shown in the same web page side by side.

The Ruby on Rails version has a built-in Unit Test Suite that fully exorcises the code using a wide variety of test conditions that provides good code coverage.

The other code samples are not web based, as they have been presented however they could all be published via the web using their respective techniques for doing so.

About these ads

About Ray C Horn
See my profile at http://www.linkedin.com/in/raychorn with more than 1286+ connections and growing all the time.

One Response to One Project, Six or Seven, Maybe Eight Languages…

  1. Pingback: One Project, Nine Languages… « Agile Developer's Blog

Follow

Get every new post delivered to your Inbox.

Join 312 other followers

%d bloggers like this: