Fictizia / Curso-JS-para-desarrolladores-web_ed7

FICTIZIA » Curso de JavaScript para desarrolladores web — 7ª Edición
19 stars 7 forks source link

Reto Navideño #9

Closed UlisesGascon closed 7 years ago

UlisesGascon commented 7 years ago

NASA Rover Challenge

Context

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. The problem specified below requires a solution that receives input, does some processing and then returns some output.

Specification

A robotic rover is to be landed by NASA on a plateau on Mars. This plateau, which is curiously square, must be navigated by the rover so that its 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 coordinates 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 parameter is the size of the square (the lower-left coordinates are assumed to be 0,0).

The rest of parameters is information pertaining to the rover that has been deployed.

The second argument gives the rover's position, and the third is a series of instructions telling the rover how to explore the plateau. The position is made up of two integers and a letter, corresponding to the x and y coordinates and the rover's orientation.

Output:

The output should be the final coordinates and heading.

Example: function setup(5, “1 2 N”, [“L”, “M”, “L”, “M”, “L”, “M”, “L”, “M”, “M”]) Expected Output: “1 3 N”

phegraphic commented 7 years ago

No entiendo exactamente que hay que hacer. No comprendo bien el enunciado del problema.

LeylaVieira commented 7 years ago

Hola phegraphic, lo que debes hacer es simular el recorrido que hace el rover en un "tablero". De acuerdo a lo que explican, la función principal debe recibir tres parámetros:

1 - un número : es el tamaño del "tablero" 2 - una cadena : es la posición inicial del rover (coordenadas "X", "Y" y orientación: puede ser Norte, Sur, Este u Oeste, separadas por espacios) 3 - un array : que son los movimientos que debe hacer el rover ( "L" para girar 90º a la izquierda, "R" para girar 90º a la derecha y "M" para avanzar uno)

Para tenerlo claro, a partir de esta llamada setup(5, “1 2 N”, [“L”, “M”, “L”, “M”, “L”, “M”, “L”, “M”, “M”]) he dibujado este recorrido:

pasos

Resumiendo, el rover (la flecha en azul es la posición inicial y en rojo la final) hace esto:

resumen

Y como ves, la posición final del rover después de seguir las instrucciones es: 1 en "X", 3 en "Y" en sentido N (norte)

Espero que mi explicación te sea útil para resolver el problema :smile:

UlisesGascon commented 7 years ago

@LeylaVieira Bravo! Super bien explicado y además ilustrado!

UlisesGascon commented 7 years ago

Os comparto una solución