Shiva Navaneeth
Shiva Navaneeth

Reputation: 25

15 by 15 coordinate finding output

I've been given a programing task to complete. Find the end coordinate location when given a start point heading north and using simple commands left, right and forward.

A example scenario which was provided is as follows:

Starting input 5,5 RFLFRFLF and the output position the task says to be is 7,7 however I do not get that answer when simply doing it by hand.

Any suggestions in how they got the outcome coordinate to be 7,7

Upvotes: 0

Views: 80

Answers (1)

randal4
randal4

Reputation: 590

The R and L are telling which direction to TURN, not to MOVE. So going through the example starting at 5,5.

  • turn right, now still at 5,5 but facing east.
  • move forward, now at 6,5 still facing east
  • turn left, now still at 6, 5 but facing north
  • move forward, now at 6,6 facing north
  • turn right, still at 6,6 facing east
  • move forward, now at 7,6 facing east
  • turn left, still at 7,6 now facing north
  • move forward, now at 7,7.

Upvotes: 2

Related Questions