Perl 219
My perl version is 392 342 characters long (I had to handle the case of the beam hitting the laser):
Update, thanks Hobbs for reminding me of tr//
, it's now 250 characters:
Update, removing the m
in m//
, changing the two while
loops brought a few savings; there's now only one space required.
(L:it;goto L
is the same length as do{it;redo}
):
@b=map{($y,$x,$s)=($a,$-[0],$&)if/[<>^v]/;$a++;[split//]}<>;L:$_=$s;$x++if/>/;
$x--if/;$y++if/v/;$y--if/\^/;$_=$b[$y][$x];die"true\n"if/x/;die"false\n"if
/[<>^v#]/;$s=~tr/<>^v/^v<>/if/\\/;$s=~tr/<>^v/v^>
I shaved some, but it barelyjust competes with some of these, albeit late.
It looks a little better as:
#!/usr/bin/perl
@b = map {
($y, $x, $s) = ($a, $-[0], $&) if /[<>^v]/;
$a++;
[split//]
} <>;
L:
$_ = $s;
$x++ if />/;
$x-- if /;
$y++ if /v/;
$y-- if /\^/;
$_ = $b[$y][$x];
die "true\n" if /x/;
die "false\n" if /[<>^v#]/;
$s =~ tr/<>^v/^v<>/ if /\\/;
$s =~ tr/<>^v/v^> if /\//;
goto L
Well... Honestly this should be self explanatory if you understand that the @b
is an array arrays of characters in each line, and can read the simple regexp and tr
statements.