Skip to main content
deleted 55 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11

Perl, 702 613 546 474 439 338 262260 bytes

Thanks to Dom Hastings for his help and his supergolfed version.
The code uses a 2D array since printing backwards and upwards is a pain.

Final versionVersion by Dom Hastings:

$x=$y=$a=$b=99;map{/^./;$a=($c=$x)<$a?$x:$a,$A=$x>$A?$x:$A,$b=($C=$y)<$b?$y:$b,$B=$y>$B?$y:$B,$q[$c][$C]={split'','W<E>N^Sv'}->{$&},$x+={W,-1,E,1}->{$&},$y+={N,-1,S,1}->{$&}for 1..$'}split',',pop;$q[$c][$C]=X;mappop;$q[$c][$C]=X;for$y($b..$B){$y=$_;print$q[$_][$y]||$"for$aprint$q[$_][$y]||$"for$a..$A;print$/}$b..$B

My lesser golfed version of 338 bytes (for reference):

@m=split(',',pop);$x=$y=$a=$b=99;map{($d,$s)=/^(.)(.+)$/;for(1..$s){$c=$x;$C=$y;if($x<$a){$a=$x}if($x>$A){$A=$x}if($y<$b){$b=$y}if($y>$B){$B=$y}if($d eq"W"){$r="<";$x--}if($d eq"E"){$r=">";$x++}if($d eq"N"){$r="^";$y--}if($d eq"S"){$r=v;$y++}$q[$c][$C]=$r}}@m;$q[$c][$C]=X;for$y($b..$B){for$x($a..$A){$t=$q[$x][$y];print$t?$t:$"}print$/}

Test

$ perl piratemap_golf.pl E4,N3,W6,S10,W1,S1,E5,N1,W2,N6,E6,N5,W10,S1,E2
v<<<<<<<<<<
>Xv<<<<<< ^
  v     ^ ^
  v     ^ ^
  v >>>>^ ^
  v >>>>>>^
  v ^
  v ^
  v ^
  v ^
  v ^
 v< ^<<
 >>>>>^

Perl, 702 613 546 474 439 338 262 bytes

Thanks to Dom Hastings for his help and his supergolfed version.
The code uses a 2D array since printing backwards and upwards is a pain.

Final version by Dom Hastings:

$x=$y=$a=$b=99;map{/^./;$a=($c=$x)<$a?$x:$a,$A=$x>$A?$x:$A,$b=($C=$y)<$b?$y:$b,$B=$y>$B?$y:$B,$q[$c][$C]={split'','W<E>N^Sv'}->{$&},$x+={W,-1,E,1}->{$&},$y+={N,-1,S,1}->{$&}for 1..$'}split',',pop;$q[$c][$C]=X;map{$y=$_;print$q[$_][$y]||$"for$a..$A;print$/}$b..$B

My lesser golfed version of 338 bytes (for reference):

@m=split(',',pop);$x=$y=$a=$b=99;map{($d,$s)=/^(.)(.+)$/;for(1..$s){$c=$x;$C=$y;if($x<$a){$a=$x}if($x>$A){$A=$x}if($y<$b){$b=$y}if($y>$B){$B=$y}if($d eq"W"){$r="<";$x--}if($d eq"E"){$r=">";$x++}if($d eq"N"){$r="^";$y--}if($d eq"S"){$r=v;$y++}$q[$c][$C]=$r}}@m;$q[$c][$C]=X;for$y($b..$B){for$x($a..$A){$t=$q[$x][$y];print$t?$t:$"}print$/}

Test

$ perl piratemap_golf.pl E4,N3,W6,S10,W1,S1,E5,N1,W2,N6,E6,N5,W10,S1,E2
v<<<<<<<<<<
>Xv<<<<<< ^
  v     ^ ^
  v     ^ ^
  v >>>>^ ^
  v >>>>>>^
  v ^
  v ^
  v ^
  v ^
  v ^
 v< ^<<
 >>>>>^

Perl, 702 613 546 474 439 338 260 bytes

Thanks to Dom Hastings for his help and his supergolfed version.
The code uses a 2D array.

Version by Dom Hastings:

$x=$y=$a=$b=99;map{/^./;$a=($c=$x)<$a?$x:$a,$A=$x>$A?$x:$A,$b=($C=$y)<$b?$y:$b,$B=$y>$B?$y:$B,$q[$c][$C]={split'','W<E>N^Sv'}->{$&},$x+={W,-1,E,1}->{$&},$y+={N,-1,S,1}->{$&}for 1..$'}split',',pop;$q[$c][$C]=X;for$y($b..$B){print$q[$_][$y]||$"for$a..$A;print$/}

My lesser golfed version of 338 bytes (for reference):

@m=split(',',pop);$x=$y=$a=$b=99;map{($d,$s)=/^(.)(.+)$/;for(1..$s){$c=$x;$C=$y;if($x<$a){$a=$x}if($x>$A){$A=$x}if($y<$b){$b=$y}if($y>$B){$B=$y}if($d eq"W"){$r="<";$x--}if($d eq"E"){$r=">";$x++}if($d eq"N"){$r="^";$y--}if($d eq"S"){$r=v;$y++}$q[$c][$C]=$r}}@m;$q[$c][$C]=X;for$y($b..$B){for$x($a..$A){$t=$q[$x][$y];print$t?$t:$"}print$/}

Test

$ perl piratemap_golf.pl E4,N3,W6,S10,W1,S1,E5,N1,W2,N6,E6,N5,W10,S1,E2
v<<<<<<<<<<
>Xv<<<<<< ^
  v     ^ ^
  v     ^ ^
  v >>>>^ ^
  v >>>>>>^
  v ^
  v ^
  v ^
  v ^
  v ^
 v< ^<<
 >>>>>^
added 382 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11

Perl, 702 613 546 474 439 338338 262 bytes

Perhaps still long comparedThanks to othersDom Hastings for his help and his supergolfed version.
Using anThe code uses a 2D array might not have been the best tactic to achieve minimal code. But hey, I triedsince printing backwards and upwards is a pain.  

Final version by Dom Hastings:

$x=$y=$a=$b=99;map{/^./;$a=($c=$x)<$a?$x:$a,$A=$x>$A?$x:$A,$b=($C=$y)<$b?$y:$b,$B=$y>$B?$y:$B,$q[$c][$C]={split'','W<E>N^Sv'}->{$&},$x+={W,-1,E,1}->{$&},$y+={N,-1,S,1}->{$&}for 1..$'}split',',pop;$q[$c][$C]=X;map{$y=$_;print$q[$_][$y]||$"for$a..$A;print$/}$b..$B

My lesser golfed version of 338 bytes (for reference):

  
@m=split(',',pop);$x=$y=$a=$b=99;map{($d,$s)=/^(.)(.+)$/;for(1..$s){$c=$x;$C=$y;if($x<$a){$a=$x}if($x>$A){$A=$x}if($y<$b){$b=$y}if($y>$B){$B=$y}if($d eq"W"){$r="<";$x--}if($d eq"E"){$r=">";$x++}if($d eq"N"){$r="^";$y--}if($d eq"S"){$r=v;$y++}$q[$c][$C]=$r}}@m;$q[$c][$C]=X;for$y($b..$B){for$x($a..$A){$t=$q[$x][$y];print$t?$t:$"}print$/}

Test

$ perl piratemap_golf.pl E4,N3,W6,S10,W1,S1,E5,N1,W2,N6,E6,N5,W10,S1,E2
v<<<<<<<<<<
>Xv<<<<<< ^
  v     ^ ^
  v     ^ ^
  v >>>>^ ^
  v >>>>>>^
  v ^
  v ^
  v ^
  v ^
  v ^
 v< ^<<
 >>>>>^

Perl, 702 613 546 474 439 338 bytes

Perhaps still long compared to others.
Using an 2D array might not have been the best tactic to achieve minimal code. But hey, I tried.  :)

 
@m=split(',',pop);$x=$y=$a=$b=99;map{($d,$s)=/^(.)(.+)$/;for(1..$s){$c=$x;$C=$y;if($x<$a){$a=$x}if($x>$A){$A=$x}if($y<$b){$b=$y}if($y>$B){$B=$y}if($d eq"W"){$r="<";$x--}if($d eq"E"){$r=">";$x++}if($d eq"N"){$r="^";$y--}if($d eq"S"){$r=v;$y++}$q[$c][$C]=$r}}@m;$q[$c][$C]=X;for$y($b..$B){for$x($a..$A){$t=$q[$x][$y];print$t?$t:$"}print$/}

Test

$ perl piratemap_golf.pl E4,N3,W6,S10,W1,S1,E5,N1,W2,N6,E6,N5,W10,S1,E2
v<<<<<<<<<<
>Xv<<<<<< ^
  v     ^ ^
  v     ^ ^
  v >>>>^ ^
  v >>>>>>^
  v ^
  v ^
  v ^
  v ^
  v ^
 v< ^<<
 >>>>>^

Perl, 702 613 546 474 439 338 262 bytes

Thanks to Dom Hastings for his help and his supergolfed version.
The code uses a 2D array since printing backwards and upwards is a pain.

Final version by Dom Hastings:

$x=$y=$a=$b=99;map{/^./;$a=($c=$x)<$a?$x:$a,$A=$x>$A?$x:$A,$b=($C=$y)<$b?$y:$b,$B=$y>$B?$y:$B,$q[$c][$C]={split'','W<E>N^Sv'}->{$&},$x+={W,-1,E,1}->{$&},$y+={N,-1,S,1}->{$&}for 1..$'}split',',pop;$q[$c][$C]=X;map{$y=$_;print$q[$_][$y]||$"for$a..$A;print$/}$b..$B

My lesser golfed version of 338 bytes (for reference):

 
@m=split(',',pop);$x=$y=$a=$b=99;map{($d,$s)=/^(.)(.+)$/;for(1..$s){$c=$x;$C=$y;if($x<$a){$a=$x}if($x>$A){$A=$x}if($y<$b){$b=$y}if($y>$B){$B=$y}if($d eq"W"){$r="<";$x--}if($d eq"E"){$r=">";$x++}if($d eq"N"){$r="^";$y--}if($d eq"S"){$r=v;$y++}$q[$c][$C]=$r}}@m;$q[$c][$C]=X;for$y($b..$B){for$x($a..$A){$t=$q[$x][$y];print$t?$t:$"}print$/}

Test

$ perl piratemap_golf.pl E4,N3,W6,S10,W1,S1,E5,N1,W2,N6,E6,N5,W10,S1,E2
v<<<<<<<<<<
>Xv<<<<<< ^
  v     ^ ^
  v     ^ ^
  v >>>>^ ^
  v >>>>>>^
  v ^
  v ^
  v ^
  v ^
  v ^
 v< ^<<
 >>>>>^
added 84 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11

Perl, 702 613 546 474 439 338 bytes

Perhaps still long compared to others.
Using an 2D array might not have been the best tactic to achieve minimal code. But hey, I tried. :)

@m=split(',',pop);$x=$y=$a=$b=99;map{($d,$s)=/^(.)(.+)$/;for(1..$s){$c=$x;$C=$y;if($x<$a){$a=$x}if($x>$A){$A=$x}if($y<$b){$b=$y}if($y>$B){$B=$y}if($d eq"W"){$r="<";$x--}if($d eq"E"){$r=">";$x++}if($d eq"N"){$r="^";$y--}if($d eq"S"){$r=v;$y++}$q[$c][$C]=$r}}@m;$q[$c][$C]=X;for$y($b..$B){for$x($a..$A){$t=$q[$x][$y];print$t?$t:$"}print$/}

Test

$ perl piratemappiratemap_golf.pl "N10E4,E6N3,S5W6,W4S10,W1,S1,E5,N1,E3W2,N3N6,W4E6,S10" N5,W10,S1,E2
v<<<<<<<<<<
>Xv<<<<<< ^
>>>>>>v  v     ^ ^
^v<<<<v  v     ^ ^
^v  v ^v>>>>^ ^
^v  v ^v>>>>>>^
^v>>>^v  v ^
^v^<<<<  v ^
^v  v ^
^v  v ^
^v  v ^
^v v< ^<<
^X >>>>>^

Perl, 702 613 546 474 439 338 bytes

Perhaps still long compared to others.
Using an 2D array might not have been the best tactic to achieve minimal code. But hey, I tried. :)

@m=split(',',pop);$x=$y=$a=$b=99;map{($d,$s)=/^(.)(.+)$/;for(1..$s){$c=$x;$C=$y;if($x<$a){$a=$x}if($x>$A){$A=$x}if($y<$b){$b=$y}if($y>$B){$B=$y}if($d eq"W"){$r="<";$x--}if($d eq"E"){$r=">";$x++}if($d eq"N"){$r="^";$y--}if($d eq"S"){$r=v;$y++}$q[$c][$C]=$r}}@m;$q[$c][$C]=X;for$y($b..$B){for$x($a..$A){$t=$q[$x][$y];print$t?$t:$"}print$/}

Test

$ perl piratemap.pl "N10,E6,S5,W4,N1,E3,N3,W4,S10"  
>>>>>>v
^v<<<<v
^v   ^v
^v   ^v
^v>>>^v
^v^<<<<
^v
^v
^v
^v
^X

Perl, 702 613 546 474 439 338 bytes

Perhaps still long compared to others.
Using an 2D array might not have been the best tactic to achieve minimal code. But hey, I tried. :)

@m=split(',',pop);$x=$y=$a=$b=99;map{($d,$s)=/^(.)(.+)$/;for(1..$s){$c=$x;$C=$y;if($x<$a){$a=$x}if($x>$A){$A=$x}if($y<$b){$b=$y}if($y>$B){$B=$y}if($d eq"W"){$r="<";$x--}if($d eq"E"){$r=">";$x++}if($d eq"N"){$r="^";$y--}if($d eq"S"){$r=v;$y++}$q[$c][$C]=$r}}@m;$q[$c][$C]=X;for$y($b..$B){for$x($a..$A){$t=$q[$x][$y];print$t?$t:$"}print$/}

Test

$ perl piratemap_golf.pl E4,N3,W6,S10,W1,S1,E5,N1,W2,N6,E6,N5,W10,S1,E2
v<<<<<<<<<<
>Xv<<<<<< ^
  v     ^ ^
  v     ^ ^
  v >>>>^ ^
  v >>>>>>^
  v ^
  v ^
  v ^
  v ^
  v ^
 v< ^<<
 >>>>>^
deleted 7 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
deleted 125 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
deleted 2 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
deleted 6 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
deleted 8 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
added 2 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
added 16 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
deleted 75 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
added 158 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
added 4 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
deleted 28 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
added 5 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
deleted 11 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
Formatted header, added syntax highlighting, corrected capitalization of Perl since it isn't an acronym.
Source Link
Alex A.
  • 24.7k
  • 5
  • 38
  • 119
Loading
deleted 66 characters in body
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading
Source Link
LukStorms
  • 1.8k
  • 1
  • 12
  • 11
Loading