Multiverse Mars Rover
An implementation of Mars Rover Challenge using:
- Bun - New & faster JS runtime environment (faster than V8)
- Typescript - JavaScript with syntax for types
- Jest - Testing framework
Challenge
Write a program that takes in commands and moves one or more robots around Mars.
Note: I've tweaked this challenge to support multiple planets (Mercury, Venus, Earth, etc...)
- The world should be modelled as a grid with size (m x n)
- The program should read the input, update the robots, and print out the final states of the robots
- Each robot has a position (x, y), and an orientation (N, E, S, W)
- Each robot can move forward one space (F), rotate left by 90 degrees (L), or rotate right by 90 degrees (R)
- If a robot moves off the grid, it is marked as ‘lost’ and its last valid grid position and orientation is recorded
- Going from x -> x + 1 is in the easterly direction, and y -> y + 1 is in the northerly direction. i.e. (0, 0) represents the south-west corner of the grid
Questions
- Can robots encounter obstacles? i.e. other robots? I'm assuming we don't as part of this challenge
- What happens if a robot receives a command that is not supported?
- What happens if a robot hasn't landed? (i.e. initial coordinates of robot is not valid)
- What happens if the robot is a complete bimbo? (i.e the orientation isn't valid)
- Do we have any limitations? i.e. program should run in O(n)? I don't think thats possible since each robot can have m number of commands? Maybe O(nm)?
- Can grid coordinates have negative values? - For the sake of this challenge, I have excluded this use-case
- Why doesn't the robot support backwards? - I've added this functionality
Getting Started
To run the program, you need to have Bun installed. See their doc.
Run
┌─[ multiverse-mars-rover ] on master via ⬢ v19.1.0
└─▪ git clone git@github.com:bitabs/multiverse-mars-rover.git
┌─[ multiverse-mars-rover ] on master via ⬢ v19.1.0
└─▪ cd multiverse-mars-rover
┌─[ multiverse-mars-rover ] on master via ⬢ v19.1.0
└─▪ bun install # faster than npm
┌─[ multiverse-mars-rover ] on master via ⬢ v19.1.0
└─▪ bun start # Runs the program
Test
┌─[ multiverse-mars-rover ] on master via ⬢ v19.1.0
└─▪ bun test # Runs the tests