Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active May 18, 2023 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trikitrok/ff822b9ada2e89a522340fdad5171ca7 to your computer and use it in GitHub Desktop.
Save trikitrok/ff822b9ada2e89a522340fdad5171ca7 to your computer and use it in GitHub Desktop.

Mars Rover movement

Description

In this exercise we'll implement from scratch part of the Mars Rover kata.

The rover interface would have only one method: receive(commands: string): void

This is a summary of the behavior of the rover that we'll implement:

  • It's located on a grid at some point with coordinates (x,y) and facing a direction encoded with a character.

  • The meaning of each direction character is:

    • N -> North
    • S -> South
    • E -> East
    • W -> West
  • The rover receives a sequence of commands (a string of characters) which are codified in the following way:

    • When it receives an f, it moves forward one position in the direction it is facing.
    • When it receives a b, it moves backward one position in the direction it is facing.
    • When it receives a l, it turns left changing its direction (by one step in the direction).
    • When it receives a r, it turns right changing its direction (by one step in the direction).
  • The rover ignores unknown commands.

  • The rover wraps at the edges, but be careful, it's visiting a flat planet with teleporting edges (ask the product owner once you finish implementing the rover movement).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment