Skip to main content
11 of 19
added 2 characters in body
LukStorms
  • 1.8k
  • 1
  • 12
  • 11

Perl, 702 613 546 474 455 bytes

Perhaps still long compared to others. So I assume a Perl veteran could do much better.
Using an 2D array might not have been the best tactic to achieve minimal code. But hey, I tried. :)

@m=split(',',pop);for(@m){($d,$s)=/^(.)(.+)$/;for(1..$s){if($x>$A){$A=$x}if($x<$a){$a=$x}if($y>$B){$B=$y}if($y<$b){$b=$y}$x+=E eq$d;$y+=S eq$d;$x-=W eq$d;$y-=N eq$d}}$A-=$a;$x=-$a;$B-=$b;$y=-$b;$a=$b=0;for(@m){($d,$s)=/^(.)(.+)$/;for(1..$s){$c=$x;$C=$y;if($d eq"E"){$r=">";$x++}if($d eq"S"){$r="v";$y++}if($d eq"W"){$r="<";$x--}if($d eq"N"){$r="^";$y--}$q[$c][$C]=$r}}$q[$c][$C]="X";for$y(0..$B){for$x(0..$A){print defined$q[$x][$y]?$q[$x][$y]:$"}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
LukStorms
  • 1.8k
  • 1
  • 12
  • 11