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

Perl, 702 613 546 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. :)

use Switch;@m=split(',',$ARGV[0]);foreach(@m){$d=substr($_,0,1);$s=substr($_,1);for(1..$s){if($x>$A){$A=$x}if($x<$a){$a=$x}if($y>$B){$B=$y}if($y<$b){$b=$y}
switch($d){case"N"{$y--}case"E"{$x++}case"S"{$y++}case"W"{$x--}}}}$A-=$a;$x=-$a;$a=0;$B-=$b;$y=-$b;$b=0;foreach(@m){$d=substr($_,0,1);$s=substr($_,1);for(1..$s){$c=$x;$C=$y;
switch($d){case"N"{$q[$x][$y]="^";$y--}case"E"{$q[$x][$y]=">";$x++}case"S"{$q[$x][$y]="v";$y++}case"W"{$q[$x][$y]="<";$x--}}}}$q[$c][$C]="X";for$y(0..$B){for$x(0..$A){print defined$q[$x][$y]?$q[$x][$y]:" "}print"\n"}

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