in reply to please solve this

... and you may find it easier to solve if you correct the "output" so you have only ONE "GO RIGHT" and add a "GO LEFT".

But pay special attention to the first few replies: asking us to do your homework is a loser (or even a double loser: not only will you not learn much, but you may get no more useful replies than already posted) for you and a waste of our time.

Replies are listed 'Best First'.
Re^2: please solve this
by GotToBTru (Prior) on Mar 17, 2015 at 21:49 UTC

    No, the output is correct; M is two columns to the right of G and no need for any left motions (assuming the post has not been modified between when you saw it and when I did). It will be important to developing a solution that at least one of the test cases includes movement in each direction.

    Dum Spiro Spero