Skip to main content
1 of 19
LukStorms
  • 1.8k
  • 1
  • 12
  • 11

PERL, 702

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. :)

my$m=$ARGV[0];my@m=split(',',$m);my($x,$y,$a,$b,$A,$B,$c,$C)=(0,0,0,0,0,0,0,0);foreach(@m){my$d=substr($_,0,1);my$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}if($d eq "N"){$y--}if($d eq "E"){$x++}if($d eq "S"){$y++}if($d eq "W"){$x--}}}$x=0;$y=0;if($a<0){$A-=$a;$x=0-$a;$a=0;}if($b<0){$B-=$b;$y=0-$b;$b=0;}my@q;for my$j(0..$B){for my$i(0..$A){$q[$i][$j]=" "}}foreach(@m){my$d=substr($_,0,1);my$s=substr($_,1);for(1..$s){$c=$x;$C=$y;if($d eq "E"){$q[$x][$y]=">";$x++;}if($d eq "S"){$q[$x][$y]="v";$y++;}if($d eq "W"){$q[$x][$y]="<";$x--;}if($d eq "N"){$q[$x][$y]="^";$y--;}}}$q[$c][$C]="X";for $y(0..$B){for $x(0..$A){print $q[$x][$y]}if($y<$B){print "\n"}}
LukStorms
  • 1.8k
  • 1
  • 12
  • 11