Skip to content

felipemelendez/my_Spaceship

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

My Spaceship

This was a school assignment and I solved it in C and JS, and I solved the problem in JS using two diffrent approaches.

This was the prompt:

You have been recently been hired by SpacePro, a new rocket manufacturer, and have been tasked with designing a simulator for their spaceships. This simulator creates a virtual “space” and keeps track of the basic movements and direction of a given ship. Your job is to keep track of where the ship is and it’s orientation relative to its starting point.

Instructions Your ship simulator must take in a string of letters that represent a planned flight path for a given rocket ship.

In a ship’s flight path there are only 3 valid options for movement; R for turning right, L for turning left and A for advancing.

If, for example, you receive “RRALAA” as your flight path, you should interpret it as the following: Turn right, turn right, advance, turn left, advance, advance Once given this initial flight path, your program must return the x,y coordinates of a ship’s final destination as well as it’s orientation relative to the starting point.

Orientation is represented as left, right, up or down.

Space is infinite, so the x,y coordinates you return could be placed on a seemingly infinite grid and can be negative or positive values.

So let's say an upward facing rocket ship leaves its starting point of 0,0 and is given the flight path of “RRALAA”, it’s final location will be 2,-1 and it will be facing right.

Your Job You must create a function that takes in a flight path of a rocket ship as a string of letters and returns the following format: "{x: X, y: Y, direction: 'DIRECTION'}" X,Y represent the ending coordinates of your ship and direction represents its final direction.

Notes We are using Computer Graphics Coordinate System

All spaceships will start at 0,0 and will face up Moving left/right will influence X and moving up/down will influence Y

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published