3 added 46 characters in body
source | link

Bash/SHELF, 243 235

"SHEll goLF" is a golfing library for Bash which provides a few useful aliases. This is a valid answer as the library existed and was on GitHub before the challenge was posted.

Sorry, I can't get this to work on ideone.

How to run

This takes the initial position (separated by commas as specified; this adds a lot of characters to the code) as its first argument, and the instructions on standard input.

source shelf.sh #you must load SHELF first
source rover.sh 1,2,N<<<MRMLM #now run the script via source so it has access to SHELF

Sample output

2,4,N

Code

o=$1
D(){ o=`y NESW $1<<<$o`;}
for x in `Y . '& '`;{
d $x R&&D ESWN
d $x L&&D WNES
d $x M&&z=(`y , \ <<<$o`)&&case ${z[2]} in N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac&&o=`P ${z[@]}|y \  ,`
}
p $o

Explanation

d is for comparison; it returns 0 if its two arguments are equal and 1 otherwise, it can then have other commands chained onto it with && and ||.

y is like tr (but done through sed).

Y is like sed 's/.../.../g' for its two arguments.

P is echo -e -n; p is just echo -e.

o=$1 #save first argument to variable
D(){ o=`y NESW $1<<<$o`;} #define an alias to turn R or L
for x in `Y . '& '`;{ #add a space after every character on stdin and loop for each one
d $x R&&D ESWN #turn R using alias
d $x L&&D WNES #turn L using alias

The next bit is profoundly ugly, with about 145 chars on one line. If the current command is M, turn the commas in $o into spaces, convert to array and save to $z. Then, do a switch...case block for the last element of $z (the direction the rover is pointing. Change coordinates accordingly, then convert $z back into a comma-separated string and save to $o.

d $x M&&z=(`y , \ <<<$o`)&&case ${z[2]} in N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac&&o=`P ${z[@]}|y \  ,`
} #end loop
p $o #print output

Bash/SHELF, 243 235

"SHEll goLF" is a golfing library for Bash which provides a few useful aliases. This is a valid answer as the library existed and was on GitHub before the challenge was posted.

How to run

This takes the initial position (separated by commas as specified; this adds a lot of characters to the code) as its first argument, and the instructions on standard input.

source shelf.sh #you must load SHELF first
source rover.sh 1,2,N<<<MRMLM #now run the script via source so it has access to SHELF

Sample output

2,4,N

Code

o=$1
D(){ o=`y NESW $1<<<$o`;}
for x in `Y . '& '`;{
d $x R&&D ESWN
d $x L&&D WNES
d $x M&&z=(`y , \ <<<$o`)&&case ${z[2]} in N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac&&o=`P ${z[@]}|y \  ,`
}
p $o

Explanation

d is for comparison; it returns 0 if its two arguments are equal and 1 otherwise, it can then have other commands chained onto it with && and ||.

y is like tr (but done through sed).

Y is like sed 's/.../.../g' for its two arguments.

P is echo -e -n; p is just echo -e.

o=$1 #save first argument to variable
D(){ o=`y NESW $1<<<$o`;} #define an alias to turn R or L
for x in `Y . '& '`;{ #add a space after every character on stdin and loop for each one
d $x R&&D ESWN #turn R using alias
d $x L&&D WNES #turn L using alias

The next bit is profoundly ugly, with about 145 chars on one line. If the current command is M, turn the commas in $o into spaces, convert to array and save to $z. Then, do a switch...case block for the last element of $z (the direction the rover is pointing. Change coordinates accordingly, then convert $z back into a comma-separated string and save to $o.

d $x M&&z=(`y , \ <<<$o`)&&case ${z[2]} in N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac&&o=`P ${z[@]}|y \  ,`
} #end loop
p $o #print output

Bash/SHELF, 243 235

"SHEll goLF" is a golfing library for Bash which provides a few useful aliases. This is a valid answer as the library existed and was on GitHub before the challenge was posted.

Sorry, I can't get this to work on ideone.

How to run

This takes the initial position (separated by commas as specified; this adds a lot of characters to the code) as its first argument, and the instructions on standard input.

source shelf.sh #you must load SHELF first
source rover.sh 1,2,N<<<MRMLM #now run the script via source so it has access to SHELF

Sample output

2,4,N

Code

o=$1
D(){ o=`y NESW $1<<<$o`;}
for x in `Y . '& '`;{
d $x R&&D ESWN
d $x L&&D WNES
d $x M&&z=(`y , \ <<<$o`)&&case ${z[2]} in N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac&&o=`P ${z[@]}|y \  ,`
}
p $o

Explanation

d is for comparison; it returns 0 if its two arguments are equal and 1 otherwise, it can then have other commands chained onto it with && and ||.

y is like tr (but done through sed).

Y is like sed 's/.../.../g' for its two arguments.

P is echo -e -n; p is just echo -e.

o=$1 #save first argument to variable
D(){ o=`y NESW $1<<<$o`;} #define an alias to turn R or L
for x in `Y . '& '`;{ #add a space after every character on stdin and loop for each one
d $x R&&D ESWN #turn R using alias
d $x L&&D WNES #turn L using alias

The next bit is profoundly ugly, with about 145 chars on one line. If the current command is M, turn the commas in $o into spaces, convert to array and save to $z. Then, do a switch...case block for the last element of $z (the direction the rover is pointing. Change coordinates accordingly, then convert $z back into a comma-separated string and save to $o.

d $x M&&z=(`y , \ <<<$o`)&&case ${z[2]} in N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac&&o=`P ${z[@]}|y \  ,`
} #end loop
p $o #print output
2 golfed; added 34 characters in body
source | link

Bash/SHELF, 243243 235

o=$1
D(){ o=`y NESW $1<<<$o`;}
for x in `Y . '& '`;do'`;{
d $x R&&o=`y NESWR&&D ESWN<<<$o`ESWN
d $x L&&o=`y NESWL&&D WNES<<<$o`WNES
d $x M&&{
z=M&&z=(`y , \ <<<$o`)
case&&case ${z[2]} in
  N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac
o=`Pz[0]=$[z[0]+1];;esac&&o=`P ${z[@]}|y \  ,`
}
done
p $o
o=$1               #save first argument to variable
D(){ o=`y NESW $1<<<$o`;} #define an #savealias firstto argumentturn toR aor variableL
for x in `Y . '& '`;do      '`;{ #add a space after every charcharacter on stdin, thenand loop for each one
d $x R&&o=`y NESW ESWN<<<$o` #ifR&&D itESWN is#turn R, change $o to turnusing rightalias
d $x L&&o=`yL&&D NESWWNES WNES<<<$o`#turn #similarlyL forusing Lalias

The next bit is profoundly ugly, with about 145 chars on one line. If the current command is M, turn the commas in $o into spaces, convert to array and save to $z. Then, do a switch...case block for the last element of $z (the direction the rover is pointing. Change coordinates accordingly, then convert $z back into a comma-separated string and save to $o.

d $x M&&{                    #if it is M,
z=M&&z=(`y , \ <<<$o`)            #replace commas with spaces and convert to array
case&&case ${z[2]} in              #switch...case statement
#adjust the coordinates in the array, depending on where the rover is facing 
N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac
#turn the data back into a comma-separated string
o=`Pz[0]=$[z[0]+1];;esac&&o=`P ${z[@]}|y \  ,`
}
done #end loop
p $o #print output

Bash/SHELF, 243

o=$1
for x in `Y . '& '`;do
d $x R&&o=`y NESW ESWN<<<$o`
d $x L&&o=`y NESW WNES<<<$o`
d $x M&&{
z=(`y , \ <<<$o`)
case ${z[2]} in
 N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac
o=`P ${z[@]}|y \  ,`
}
done
p $o
o=$1                         #save first argument to a variable
for x in `Y . '& '`;do       #add a space after every char on stdin, then loop for each one
d $x R&&o=`y NESW ESWN<<<$o` #if it is R, change $o to turn right
d $x L&&o=`y NESW WNES<<<$o` #similarly for L
d $x M&&{                    #if it is M,
z=(`y , \ <<<$o`)            #replace commas with spaces and convert to array
case ${z[2]} in              #switch...case statement
#adjust the coordinates in the array, depending on where the rover is facing 
N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac
#turn the data back into a comma-separated string
o=`P ${z[@]}|y \  ,`
}
done #end loop
p $o #print output

Bash/SHELF, 243 235

o=$1
D(){ o=`y NESW $1<<<$o`;}
for x in `Y . '& '`;{
d $x R&&D ESWN
d $x L&&D WNES
d $x M&&z=(`y , \ <<<$o`)&&case ${z[2]} in N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac&&o=`P ${z[@]}|y \  ,`
}
p $o
o=$1 #save first argument to variable
D(){ o=`y NESW $1<<<$o`;} #define an alias to turn R or L
for x in `Y . '& '`;{ #add a space after every character on stdin and loop for each one
d $x R&&D ESWN #turn R using alias
d $x L&&D WNES #turn L using alias

The next bit is profoundly ugly, with about 145 chars on one line. If the current command is M, turn the commas in $o into spaces, convert to array and save to $z. Then, do a switch...case block for the last element of $z (the direction the rover is pointing. Change coordinates accordingly, then convert $z back into a comma-separated string and save to $o.

d $x M&&z=(`y , \ <<<$o`)&&case ${z[2]} in N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac&&o=`P ${z[@]}|y \  ,`
} #end loop
p $o #print output
1
source | link

Bash/SHELF, 243

"SHEll goLF" is a golfing library for Bash which provides a few useful aliases. This is a valid answer as the library existed and was on GitHub before the challenge was posted.

How to run

This takes the initial position (separated by commas as specified; this adds a lot of characters to the code) as its first argument, and the instructions on standard input.

source shelf.sh #you must load SHELF first
source rover.sh 1,2,N<<<MRMLM #now run the script via source so it has access to SHELF

Sample output

2,4,N

Code

o=$1
for x in `Y . '& '`;do
d $x R&&o=`y NESW ESWN<<<$o`
d $x L&&o=`y NESW WNES<<<$o`
d $x M&&{
z=(`y , \ <<<$o`)
case ${z[2]} in
N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac
o=`P ${z[@]}|y \  ,`
}
done
p $o

Explanation

d is for comparison; it returns 0 if its two arguments are equal and 1 otherwise, it can then have other commands chained onto it with && and ||.

y is like tr (but done through sed).

Y is like sed 's/.../.../g' for its two arguments.

P is echo -e -n; p is just echo -e.

o=$1                         #save first argument to a variable
for x in `Y . '& '`;do       #add a space after every char on stdin, then loop for each one
d $x R&&o=`y NESW ESWN<<<$o` #if it is R, change $o to turn right
d $x L&&o=`y NESW WNES<<<$o` #similarly for L
d $x M&&{                    #if it is M,
z=(`y , \ <<<$o`)            #replace commas with spaces and convert to array
case ${z[2]} in              #switch...case statement
#adjust the coordinates in the array, depending on where the rover is facing 
N) z[1]=$[z[1]+1];;S) z[1]=$[z[1]-1];;W) z[0]=$[z[0]-1];;E) z[0]=$[z[0]+1];;esac
#turn the data back into a comma-separated string
o=`P ${z[@]}|y \  ,`
}
done #end loop
p $o #print output