Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Not in a mind of taking this apart completely, but there are some hints:</p> <ul> <li><code>'-' - '-'</code> is obfuscated for <code>0</code></li> <li><code>'/' / '/'</code> and the <code>i / i</code> in read() are obfuscated for <code>1</code></li> </ul> <p>Remember that [] is commutative, i.e. <code>i["]&lt;i;++i){--i;}"]</code> is the same as <code>"]&lt;i;++i){--i;}"[i]</code> (having a char array and pointing at the i'th element of it). The <em>content</em> of the string doesn't matter in any way, only its <em>length</em> is used to define the number of iterations of the loop. Any other string of the same length (incidentially, the same length as the output...) would work. After that number of iterations, "string"[i] returns the null character that terminates the string. Zero == false, loop terminates.</p> <p>With that, it should be comparatively easy to figure out the rest.</p> <p><strong>Edit:</strong> The upvotes made me interested enough to look at this some more.</p> <p>Of course, <code>i++ + "Hello, world!\n"</code> is the same as <code>"Hello, world!\n"[ i++ ]</code>.</p> <p>codelark already pointed out that <code>0</code> is the fid for stdout. (Give <em>him</em> +1 for that, not me. Just mentioning it for completeness.)</p> <p>The <code>i</code> in <code>read()</code> is of course local, i.e. the <code>i--</code> in <code>read()</code> does not affect the <code>i</code> in <code>main()</code>. Since the following <code>i / i</code> is always <code>1</code> anyway, the <code>--</code> operator does nothing at all.</p> <p>Oh, and tell the interviewer to fire whoever wrote this code. <em>It does not do error checking on the return value of <code>write()</code>.</em> I can live with notoriously badly-written code (and have, for many years), but not checking for errors is worse than bad, that's <em>faulty</em>. :-)</p> <p>The rest is just some third-grade maths. I'd pass that to an intern. ;-)</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