Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>c (K&amp;R) 339 necessary characters after more suggestions from strager.</h2> <p>The physicist in me noted that the propagation and reflection operations are time-reversal invariant, so this version, throws rays <em>from the target</em> and checks to see if the arrive at the laser emitter. </p> <p>The rest of the implementation is very straight forward and is taken more or less exactly from my earlier, forward going effort.</p> <p>Compressed:</p> <pre><code>#define R return #define C case #define Z x,y int c,i,j,m[99][99],Z;s(d,e,Z){for(;;)switch(m[x+=d][y+=e]){C'^':R 1==e; C'&gt;':R-1==d;C'v':R-1==e;C'&lt;':R 1==d;C'#':C'x':R 0;C 92:e=-e;d=-d;C'/':c=d; d=-e;e=-c;}}main(){while((c=getchar())&gt;0)c==10?i=0,j++:(c==120?x=i,y=j: i,m[i++][j]=c);puts(s(1,0,Z)|s(0,1,Z)|s(-1,0,Z)|s(0,-1,Z)?"true":"false");} </code></pre> <p>Uncompressed(ish):</p> <pre><code>#define R return #define C case #define Z x,y int c,i,j,m[99][99],Z; s(d,e,Z) { for(;;) switch(m[x+=d][y+=e]){ C'^': R 1==e; C'&gt;': R-1==d; C'v': R-1==e; C'&lt;': R 1==d; C'#': C'x': R 0; C 92: e=-e; d=-d; C'/': c=d; d=-e; e=-c; } } main(){ while((c=getchar())&gt;0) c==10?i=0,j++: (c==120?x=i,y=j:i,m[i++][j]=c); puts(s(1,0,Z)|s(0,1,Z)|s(-1,0,Z)|s(0,-1,Z)?"true":"false"); } </code></pre> <p>There is no input validation, and bad input can send it into an infinite loop. Works properly with input no larger than 99 by 99. Requires a compiler that will link the standard library without including any of the headers. And I think I'm done, <a href="https://stackoverflow.com/questions/1480023/code-golf-lasers/1480208#1480208">strager has me beat</a> by a considerable stretch, even with his help.</p> <p>I'm rather hoping someone will demonstrate a more subtle way to accomplish the task. There s nothing wrong with this, but it is not deep magic.</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