Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>Perl, <strike>166</strike> 160 characters</h2> <p>Perl, <strike>251</strike> <strike>248</strike> <strike>246</strike> <strike>222</strike> <strike>214</strike> <strike>208</strike> <strike>203</strike> <strike>201</strike> <strike>193</strike> <strike>190</strike> <strike>180</strike> <strike>176</strike> <strike>173</strike> <strike>170</strike> 166 --> 160 chars. </p> <p>Solution had 166 strokes when this contest ended, but A. Rex has found a couple ways to shave off 6 more characters:</p> <pre><code>s!.!$t{$s++}=$&amp;!ge,$s=$r+=99for&lt;&gt;;%d='&gt;.^1&lt;2v3'=~/./g;($r)=grep$d|=$d{$t{$_}},%t; {$_=$t{$r+=(1,-99,-1,99)[$d^=3*/\\/+m&lt;/&gt;]};/[\/\\ ]/&amp;&amp;redo}die/x/?true:false,$/ </code></pre> <p>The first line loads the input into <code>%t</code>, a table of the board where <code>$t{99*i+j}</code> holds the character at row <em>i</em>,column <em>j</em>. Then,</p> <pre><code>%d=split//,'&gt;.^1&lt;2v3' ; ($r)=grep{$d|=$d{$t{$_}}}%t </code></pre> <p>it searches the elements of <code>%t</code> for a character that matches <code>&gt; ^ &lt;</code> or <code>v</code>, and simultaneously sets <code>$d</code> to a value between 0 and 3 that indicates the initial direction of the laser beam.</p> <p>At the beginning of each iteration in the main loop, we update <code>$d</code> if the beam is currently on a mirror. XOR'ing by 3 gives the correct behavior for a <code>\</code> mirror and XOR'ing by 1 gives the correct behavior for a <code>/</code> mirror.</p> <pre><code>$d^=3*/\\/+m&lt;/&gt; </code></pre> <p>Next, the current position <code>$r</code> is updated accoring to the current direction.</p> <pre><code>$r+=(1,-99,-1,99)[$d] ; $_ = $t{$r} </code></pre> <p>We assign the character at the current position to <code>$_</code> to make convenient use of the match operators.</p> <pre><code>/[\/\\ ]/ &amp;&amp; redo </code></pre> <p>Continue if we are on a blank space or a mirror character. Otherwise we terminate <code>true</code> if we are on the target (<code>$_ =~ /x/</code>) and <code>false</code> otherwise.</p> <p>Limitation: may not work on problems with more than 99 columns. This limitation could be removed at the expense of 3 more characters,</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload