add hack-a-round for language specified markdown code blocks

When language is specified in a markdown code block such as:

````
```c
    printf("Hello, world!\n");
```
````

is used, the resulting HTML as produced by `pandoc(1)` combined
with our revised `ioccc.css` is not intent the code block well.

A temporary "_hack-a-round_" is to turn the "markdown code language
specifier" into an HTML comment.  For example:

````
```<!---c-->
    printf("Hello, world!\n");
```
````

This commits turns off existing markdown code language specifiers
for now, while preserving our ability to restore them in the future
when a better  "_hack-a-round_" to the "markdown code language
specifier" problem is found.

The HTML impact if this "_hack-a-round_" is to produce HTML that
looks like this:

```
<pre class="&lt;!---c--&gt;"><code> .. </code></pre>
```

We might be able to create a complex set of classes for each markdown
code language (there won't be very many) in `ioccc.css`, or we might
find a more general CSS (or maybe `pandoc(1)`?) solution.

For now, this hack-a-round will have to do.
This commit is contained in:
Landon Curt Noll committed 2024-04-04 14:50:38 -07:00
1 parent 3919df50fb
commit b66c79254a
700 files changed
+7052 -7056

No files matched your search

+6 -6
View File
@@ -1,6 +1,6 @@
## To build:
```sh
```<!---sh-->
make
```
@@ -22,7 +22,7 @@ For more detailed information see [2018 algmyr bugs](../../bugs.html#2018_algmyr
## To use:
```sh
```<!---sh-->
./prog < prog.c # Print garbage: might mess up your terminal
./prog <file1> <file2> > out.raw
./prog -d 2 0 out.raw # Decode the first (0th) channel out of two
@@ -31,7 +31,7 @@ For more detailed information see [2018 algmyr bugs](../../bugs.html#2018_algmyr
## Try:
```sh
```<!---sh-->
./try.sh
```
@@ -164,13 +164,13 @@ standards compliant). This is used to print the usage instructions.
Compiling using
```sh
```<!---sh-->
gcc -Wall -Wextra -pedantic
```
gives only `-Wmisleading-indentation` which is sensible considering the source code. While
```sh
```<!---sh-->
clang -Wall -Wextra -pedantic
```
@@ -179,7 +179,7 @@ bodies), `-Wstring-plus-int` (since apparently some people think string+`int` is
concatenation) and one of the weirder warnings I have seen from me splitting a
negative constant with whitespace. Compiling using
```sh
```<!---sh-->
clang -Wall -Wextra -pedantic -Weverything
```
+8 -8
View File
@@ -141,7 +141,7 @@ Location: <a href="../../location.html#SE">SE</a> - <em>Kingdom of Sweden</em> (
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<p>To use this entry requires, in some invocations, a sound processing program.
This can be ALSA or SoX but we recommend the latter. See <a href="../../faq.html#sox">FAQ 3.10 - How do I
compile and use an IOCCC entry that requires sound?</a>.</p>
@@ -150,11 +150,11 @@ compile and use an IOCCC entry that requires sound?</a>.</p>
<pre><code> STATUS: INABIAF - please **DO NOT** fix</code></pre>
<p>For more detailed information see <a href="../../bugs.html#2018_algmyr">2018 algmyr bugs</a>.</p>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op">&lt;</span> prog.c <span class="co"># Print garbage: might mess up your terminal</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op">&lt;</span>file1<span class="op">&gt;</span> <span class="op">&lt;</span>file2<span class="op">&gt;</span> <span class="op">&gt;</span> out.raw</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="at">-d</span> 2 0 out.raw <span class="co"># Decode the first (0th) channel out of two</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog &lt; prog.c # Print garbage: might mess up your terminal
./prog &lt;file1&gt; &lt;file2&gt; &gt; out.raw
./prog -d 2 0 out.raw # Decode the first (0th) channel out of two</code></pre>
<h2 id="try">Try:</h2>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.sh</code></pre>
<h2 id="judges-remarks">Judges’ remarks:</h2>
<p>Be warned, this is not your garden variety text-to-speech program! Earplugs are advised,
or at least a handy and well-tested volume knob.</p>
@@ -242,14 +242,14 @@ additional logic? Answer: <code>ungetc(3)</code> into <code>stdin</code>, one <c
standards compliant). This is used to print the usage instructions.</p>
<h3 id="compilation-warnings">Compilation warnings</h3>
<p>Compiling using</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">gcc</span> <span class="at">-Wall</span> <span class="at">-Wextra</span> <span class="at">-pedantic</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> gcc -Wall -Wextra -pedantic</code></pre>
<p>gives only <code>-Wmisleading-indentation</code> which is sensible considering the source code. While</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">clang</span> <span class="at">-Wall</span> <span class="at">-Wextra</span> <span class="at">-pedantic</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> clang -Wall -Wextra -pedantic</code></pre>
<p>is a bit more pessimistic and gives <code>-Wempty-body</code> (I like loops without
bodies), <code>-Wstring-plus-int</code> (since apparently some people think string+<code>int</code> is a
concatenation) and one of the weirder warnings I have seen from me splitting a
negative constant with whitespace. Compiling using</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">clang</span> <span class="at">-Wall</span> <span class="at">-Wextra</span> <span class="at">-pedantic</span> <span class="at">-Weverything</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> clang -Wall -Wextra -pedantic -Weverything</code></pre>
<p>produces a few page faults of warnings and makes me feel generally bad about
myself. :(</p>
<h3 id="misc">Misc</h3>
+6 -6
View File
@@ -1,6 +1,6 @@
## To build:
```sh
```<!---sh-->
make
```
@@ -10,14 +10,14 @@ code](#alternate-code) below for more details.
## To use:
```sh
```<!---sh-->
./prog < textfile
```
## Try:
```sh
```<!---sh-->
./try.sh
```
@@ -31,7 +31,7 @@ it was not the shape of the Roman V that we, or the compiler, didn't like.
### Alternate build:
```sh
```<!---sh-->
make alt
```
@@ -43,7 +43,7 @@ Use `prog.alt` as you would `prog` above.
### Alternate try:
```sh
```<!---sh-->
./try.alt.sh
```
@@ -58,7 +58,7 @@ down](http://en.wikipedia.org/wiki/River_%28typography%29)!
### Compiling the program:
```sh
```<!---sh-->
cc -Wall -Wextra -Wpedantic -O3 -std=c11 prog.c -o prog
```
+6 -6
View File
@@ -141,29 +141,29 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<p>There is an alternate version of this entry. See <a href="#alternate-code">Alternate
code</a> below for more details.</p>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op">&lt;</span> textfile</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog &lt; textfile</code></pre>
<h2 id="try">Try:</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.sh</code></pre>
<h2 id="alternate-code">Alternate code:</h2>
<p>Compare <a href="prog.c">prog.c</a> and <a href="prog.alt.c">prog.alt.c</a> and find out why we had to
modify the entry, and what confused the author (see the author’s remarks). No,
it was not the shape of the Roman V that we, or the compiler, didn’t like.</p>
<h3 id="alternate-build">Alternate build:</h3>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> alt</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make alt</code></pre>
<h3 id="alternate-use">Alternate use:</h3>
<p>Use <code>prog.alt</code> as you would <code>prog</code> above.</p>
<h3 id="alternate-try">Alternate try:</h3>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.alt.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.alt.sh</code></pre>
<h2 id="judges-remarks">Judges’ remarks:</h2>
<p>With this entry, you won’t need to turn your monitor <a href="http://en.wikipedia.org/wiki/River_%28typography%29">upside
down</a>!</p>
<h2 id="authors-remarks">Author’s remarks:</h2>
<h3 id="compiling-the-program">Compiling the program:</h3>
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> <span class="at">-Wall</span> <span class="at">-Wextra</span> <span class="at">-Wpedantic</span> <span class="at">-O3</span> <span class="at">-std</span><span class="op">=</span>c11 prog.c <span class="at">-o</span> prog</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> cc -Wall -Wextra -Wpedantic -O3 -std=c11 prog.c -o prog</code></pre>
<p>Also works with a standard of C99, but C90/C89 will not compile due to
<code>for</code> loop initial declarations, along with additional warnings about
variable length arrays and lack of a <code>return</code> statement.</p>
+5 -5
View File
@@ -1,6 +1,6 @@
## To build:
```sh
```<!---sh-->
make
```
@@ -10,7 +10,7 @@ code](#alternate-code) below.
## To use:
```sh
```<!---sh-->
./prog > lena.ppm
```
@@ -21,7 +21,7 @@ First open [Lenna.png](Lenna.png) in your graphics viewer of choice. Next, after
running the above command (`./prog > lena.ppm`), open `lena.ppm` in your
graphics viewer of choice. After that try:
```sh
```<!---sh-->
./try.sh
```
@@ -44,7 +44,7 @@ for Windows.
### Alternate build:
```sh
```<!---sh-->
make alt
```
@@ -99,7 +99,7 @@ Although the program was optimized to decompress its built-in image,
it accepts to decompress image files from its standard
input. Examples:
```sh
```<!---sh-->
./prog d < lena512.bin > lena512.ppm
./prog d < fruits.bin > fruits.ppm
./prog d < vintage_cars.bin > vintage_cars.ppm
+7 -7
View File
@@ -141,16 +141,16 @@ Location: <a href="../../location.html#FR">FR</a> - <em>French Republic</em> (<e
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<p>There is an alternate version that should work with Windows. See <a href="#alternate-code">Alternate
code</a> below.</p>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op">&gt;</span> lena.ppm</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog &gt; lena.ppm</code></pre>
<h2 id="try">Try:</h2>
<p>First open <a href="Lenna.png">Lenna.png</a> in your graphics viewer of choice. Next, after
running the above command (<code>./prog &gt; lena.ppm</code>), open <code>lena.ppm</code> in your
graphics viewer of choice. After that try:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.sh</code></pre>
<p>NOTE: the script uses the tools <code>pngtopam(1)</code> (or <code>pngtopnm(1)</code> for older
versions) and <code>pnmscale</code> come from the netpbm project and <code>cjpeg(1)</code> comes from
<code>libjpeg-turbo</code>. If you don’t have these tools already see <a href="../../faq.html#netpbm">FAQ 3.15 - How do I
@@ -163,7 +163,7 @@ it?</a>.</p>
<p>The <a href="prog.alt.c">prog.alt.c</a> is based on the author’s remarks and it should work
for Windows.</p>
<h3 id="alternate-build">Alternate build:</h3>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> alt</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make alt</code></pre>
<h3 id="alternate-use">Alternate use:</h3>
<p>Use <code>prog.alt</code> as you would <code>prog</code>.</p>
<h2 id="judges-remarks">Judges’ remarks:</h2>
@@ -200,9 +200,9 @@ as the algorithms already have a significant complexity.</p>
<p>Although the program was optimized to decompress its built-in image,
it accepts to decompress image files from its standard
input. Examples:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> d <span class="op">&lt;</span> lena512.bin <span class="op">&gt;</span> lena512.ppm</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> d <span class="op">&lt;</span> fruits.bin <span class="op">&gt;</span> fruits.ppm</span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> d <span class="op">&lt;</span> vintage_cars.bin <span class="op">&gt;</span> vintage_cars.ppm</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog d &lt; lena512.bin &gt; lena512.ppm
./prog d &lt; fruits.bin &gt; fruits.ppm
./prog d &lt; vintage_cars.bin &gt; vintage_cars.ppm</code></pre>
<p>The original images for <a href="https://commons.wikimedia.org/wiki/File%3AFruits_oranges%2C_jardin_japonais_2.JPG">fruits</a> and <a href="https://commons.wikimedia.org/wiki/File%3ARed_Bull_Jungfrau_Stafette%2C_10th_stage_-_vintage_cars_%282%29.jpg">vintage cars</a> come from
Wikipedia and were resized to a width of 1024 pixels.</p>
<p>The program should be portable on any Unix system. On Windows the line
+11 -11
View File
@@ -1,6 +1,6 @@
## To build:
```sh
```<!---sh-->
make
```
@@ -10,14 +10,14 @@ code](#alternate-code) below.
## To use:
```sh
```<!---sh-->
./prog < any-file
```
## Try:
```sh
```<!---sh-->
./try.sh
```
@@ -32,7 +32,7 @@ with `-Wno-` options.
### Alternate build:
```sh
```<!---sh-->
make alt
```
@@ -82,7 +82,7 @@ and without bypassing the solution using `execve(2)`, or functions built upon it
E.g:
```c
```<!---c-->
main(){system("hd");} // it's turtles all the way down!
```
@@ -96,7 +96,7 @@ This solution is pleasing, but a true one-liner was the hoped-for goal.
Here is the 157 character version in it's entirety:
```c
```<!---c-->
char O,o[ 20];L(O){
putchar ( O+ 48+39 *(9<
O));} I(O) {L(~ 15);
@@ -115,7 +115,7 @@ The progression to the present size is interesting,
and it is interesting that the same algorithm can be expressed so differently
by slight rearrangement of its parts.
```c
```<!---c-->
// 119
char O,o[20];main(l){for(;~(l=getchar());O||puts(o))o[O++]=isprint(l)?l:46,O&=15,printf("%02x ",l);O[o]=0;O&&puts(o);}
// 116
@@ -139,7 +139,7 @@ These do not compete in the same category, since their output is materially diff
They are derived from the solutions above, but are still fascinating as concise utilities,
so here is their progression, for the curious:
```c
```<!---c-->
// 102
I;O(O){putchar(O+48+39*(9<O));}main(l){for(;~(l=getchar());O(++I&15?~15:~37))O(l>>4),O(l&15);O(-38);}
// 80
@@ -156,7 +156,7 @@ It is possible to reduce the size of each of these by one by eliding the trailin
This was not reported above since the newline kept getting appended by processing software,
and it is more interesting to remove characters by changing code than by filtering:
```sh
```<!---sh-->
$ tr -d '\012' < 109.c | wc -c
108
$ tr -d '\012' < 76.c | wc -c
@@ -257,13 +257,13 @@ the expression within the ternary remains too complex.
Try:
```sh
```<!---sh-->
cat prog.c prog.alt.c
```
or
```sh
```<!---sh-->
cmp -b prog.c prog.alt.c
```
+49 -49
View File
@@ -141,20 +141,20 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<p>There is an alternate version of this entry. See <a href="#alternate-code">Alternate
code</a> below.</p>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op">&lt;</span> any-file</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog &lt; any-file</code></pre>
<h2 id="try">Try:</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.sh</code></pre>
<h2 id="alternate-code">Alternate code:</h2>
<p>An alternate version of this entry, <a href="prog.alt.c">prog.alt.c</a>, is provided
This alternate code was supposed to compile without warnings, however
with modern compilers this is no longer the case so it will only cleanly compile
with <code>-Wno-</code> options.</p>
<h3 id="alternate-build">Alternate build:</h3>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> alt</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make alt</code></pre>
<h3 id="alternate-use">Alternate use:</h3>
<p>Use <code>prog.alt</code> as you would <code>prog</code>.</p>
<h2 id="judges-remarks">Judges’ remarks:</h2>
@@ -187,68 +187,68 @@ and without bypassing the solution using <code>execve(2)</code>, or functions bu
(<code>system(3)</code>, <code>popen(3)</code>, etc).</li>
</ul>
<p>E.g:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> main<span class="op">(){</span>system<span class="op">(</span><span class="st">&quot;hd&quot;</span><span class="op">);}</span> <span class="co">// it&#39;s turtles all the way down!</span></span></code></pre></div>
<pre class="&lt;!---c--&gt;"><code> main(){system(&quot;hd&quot;);} // it&#39;s turtles all the way down!</code></pre>
<p>is not acceptable.</p>
<p>And, “output correctly” is the output format of this entry. QED.</p>
<p>Early attempts ended up at a reasonably short 157 characters.
This was too long for a one-liner, so it had to be formatted as something more interesting.
This solution is pleasing, but a true one-liner was the hoped-for goal.
Here is the 157 character version in it’s entirety:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="dt">char</span> O<span class="op">,</span>o<span class="op">[</span> <span class="dv">20</span><span class="op">];</span>L<span class="op">(</span>O<span class="op">){</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> putchar <span class="op">(</span> O<span class="op">+</span> <span class="dv">48</span><span class="op">+</span><span class="dv">39</span> <span class="op">*(</span><span class="dv">9</span><span class="op">&lt;</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> O<span class="op">));}</span> I<span class="op">(</span>O<span class="op">)</span> <span class="op">{</span>L<span class="op">(~</span> <span class="dv">15</span><span class="op">);</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a> O<span class="op">||</span> puts<span class="op">(</span>o<span class="op">);}</span> main <span class="op">(</span>l<span class="op">){</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span><span class="op">(;~(</span>l<span class="op">=</span>getchar<span class="op">())</span> <span class="op">;</span>I<span class="op">(</span>O</span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a> <span class="op">&amp;=</span><span class="dv">15</span> <span class="op">))</span>o<span class="op">[</span> O<span class="op">++</span> <span class="op">]=</span><span class="dv">4</span><span class="op">&lt;</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a> <span class="op">(</span><span class="dv">4</span><span class="op">^</span>l <span class="op">&gt;&gt;</span><span class="dv">5</span><span class="op">)</span> <span class="op">?</span>l<span class="op">:</span> <span class="dv">46</span><span class="op">,</span>L</span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a> <span class="op">(</span>l<span class="op">&gt;&gt;</span> <span class="dv">4</span><span class="op">),</span>L <span class="op">(</span>l<span class="op">&amp;</span><span class="dv">15</span><span class="op">);</span>O<span class="op">&amp;&amp;</span></span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a> I<span class="op">(</span>o<span class="op">[</span> O<span class="op">]=</span><span class="dv">0</span> <span class="op">);}</span><span class="co">//157c</span></span></code></pre></div>
<pre class="&lt;!---c--&gt;"><code> char O,o[ 20];L(O){
putchar ( O+ 48+39 *(9&lt;
O));} I(O) {L(~ 15);
O|| puts(o);} main (l){
for(;~(l=getchar()) ;I(O
&amp;=15 ))o[ O++ ]=4&lt;
(4^l &gt;&gt;5) ?l: 46,L
(l&gt;&gt; 4),L (l&amp;15);O&amp;&amp;
I(o[ O]=0 );}//157c</code></pre>
<p>While thinking about this in the shower (you are not the only one that does this!)
came the idea which reduced the code to just 119 chars.
This dramatic reduction started to feel close to minimal, and the hunt resumed.
The progression to the present size is interesting,
and it is interesting that the same algorithm can be expressed so differently
by slight rearrangement of its parts.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="co">// 119</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="dt">char</span> O<span class="op">,</span>o<span class="op">[</span><span class="dv">20</span><span class="op">];</span>main<span class="op">(</span>l<span class="op">){</span><span class="cf">for</span><span class="op">(;~(</span>l<span class="op">=</span>getchar<span class="op">());</span>O<span class="op">||</span>puts<span class="op">(</span>o<span class="op">))</span>o<span class="op">[</span>O<span class="op">++]=</span>isprint<span class="op">(</span>l<span class="op">)?</span>l<span class="op">:</span><span class="dv">46</span><span class="op">,</span>O<span class="op">&amp;=</span><span class="dv">15</span><span class="op">,</span>printf<span class="op">(</span><span class="st">&quot;</span><span class="sc">%02x</span><span class="st"> &quot;</span><span class="op">,</span>l<span class="op">);</span>O<span class="op">[</span>o<span class="op">]=</span><span class="dv">0</span><span class="op">;</span>O<span class="op">&amp;&amp;</span>puts<span class="op">(</span>o<span class="op">);}</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a> <span class="co">// 116</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a> <span class="dt">char</span> O<span class="op">,</span>o<span class="op">[</span><span class="dv">20</span><span class="op">];</span>main<span class="op">(</span>l<span class="op">){</span><span class="cf">for</span><span class="op">(;</span>O<span class="op">++[</span>o<span class="op">]=~(</span>l<span class="op">=</span>getchar<span class="op">())?</span><span class="dv">4</span><span class="op">&lt;(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">&gt;&gt;</span><span class="dv">5</span><span class="op">)?</span>l<span class="op">:</span><span class="dv">46</span><span class="op">:</span><span class="dv">0</span><span class="op">;(</span>O<span class="op">&amp;=</span><span class="dv">15</span><span class="op">)||</span>puts<span class="op">(</span>o<span class="op">))</span>printf<span class="op">(</span><span class="st">&quot;</span><span class="sc">%02x</span><span class="st"> &quot;</span><span class="op">,</span>l<span class="op">);</span>O<span class="op">&gt;</span><span class="dv">1</span><span class="op">&amp;&amp;</span>puts<span class="op">(</span>o<span class="op">);}</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a> <span class="co">// 115</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a> <span class="dt">char</span> O<span class="op">,</span>o<span class="op">[</span><span class="dv">20</span><span class="op">];</span>main<span class="op">(</span>l<span class="op">){</span><span class="cf">for</span><span class="op">(;</span>O<span class="op">[</span>o<span class="op">]=~(</span>l<span class="op">=</span>getchar<span class="op">())?</span><span class="dv">4</span><span class="op">&lt;(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">&gt;&gt;</span><span class="dv">5</span><span class="op">)?</span>l<span class="op">:</span><span class="dv">46</span><span class="op">:</span><span class="dv">0</span><span class="op">;(</span>O<span class="op">=-~</span>O<span class="op">&amp;</span><span class="dv">15</span><span class="op">)||</span>puts<span class="op">(</span>o<span class="op">))</span>printf<span class="op">(</span><span class="st">&quot;</span><span class="sc">%02x</span><span class="st"> &quot;</span><span class="op">,</span>l<span class="op">);</span>O<span class="op">&amp;&amp;</span>puts<span class="op">(</span>o<span class="op">);}</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a> <span class="co">// 113</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a> <span class="dt">char</span> O<span class="op">,</span>o<span class="op">[</span><span class="dv">20</span><span class="op">];</span>main<span class="op">(</span>l<span class="op">){</span><span class="cf">for</span><span class="op">(;~</span>l<span class="op">;(</span>O<span class="op">=~</span>l<span class="op">?</span>printf<span class="op">(</span><span class="st">&quot;</span><span class="sc">%02x</span><span class="st"> &quot;</span><span class="op">,</span>l<span class="op">),-~</span>O<span class="op">&amp;</span><span class="dv">15</span><span class="op">:!</span>O<span class="op">)||</span>puts<span class="op">(</span>o<span class="op">))</span>O<span class="op">[</span>o<span class="op">]=~(</span>l<span class="op">=</span>getchar<span class="op">())?</span><span class="dv">4</span><span class="op">&lt;(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">&gt;&gt;</span><span class="dv">5</span><span class="op">)?</span>l<span class="op">:</span><span class="dv">46</span><span class="op">:</span><span class="dv">0</span><span class="op">;}</span></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a> <span class="co">// 112</span></span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a> <span class="dt">char</span> O<span class="op">,</span>o<span class="op">[</span><span class="dv">20</span><span class="op">];</span>main<span class="op">(</span>l<span class="op">){</span><span class="cf">for</span><span class="op">(;~</span>l<span class="op">;(</span>O<span class="op">=~</span>l<span class="op">?-~</span>O<span class="op">&amp;</span>printf<span class="op">(</span><span class="st">&quot;</span><span class="sc">%02x</span><span class="st"> &quot;</span><span class="op">,</span>l<span class="op">)*</span><span class="dv">5</span><span class="op">:!</span>O<span class="op">)||</span>puts<span class="op">(</span>o<span class="op">))</span>O<span class="op">[</span>o<span class="op">]=~(</span>l<span class="op">=</span>getchar<span class="op">())?</span><span class="dv">4</span><span class="op">&lt;(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">&gt;&gt;</span><span class="dv">5</span><span class="op">)?</span>l<span class="op">:</span><span class="dv">46</span><span class="op">:</span><span class="dv">0</span><span class="op">;}</span></span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true" tabindex="-1"></a> <span class="co">// 111</span></span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true" tabindex="-1"></a> <span class="dt">char</span> O<span class="op">,</span>o<span class="op">[</span><span class="dv">20</span><span class="op">];</span>main<span class="op">(</span>l<span class="op">){</span><span class="cf">for</span><span class="op">(;~</span>l<span class="op">;</span>O<span class="op">||</span>puts<span class="op">(</span>o<span class="op">))</span>O<span class="op">=(</span>O<span class="op">[</span>o<span class="op">]=~(</span>l<span class="op">=</span>getchar<span class="op">())?</span><span class="dv">4</span><span class="op">&lt;(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">&gt;&gt;</span><span class="dv">5</span><span class="op">)?</span>l<span class="op">:</span><span class="dv">46</span><span class="op">:</span><span class="dv">0</span><span class="op">)?-~</span>O<span class="op">&amp;</span>printf<span class="op">(</span><span class="st">&quot;</span><span class="sc">%02x</span><span class="st"> &quot;</span><span class="op">,</span>l<span class="op">)*</span><span class="dv">5</span><span class="op">:!</span>O<span class="op">;}</span></span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true" tabindex="-1"></a> <span class="co">// 110</span></span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true" tabindex="-1"></a> <span class="dt">char</span> O<span class="op">,</span>o<span class="op">[</span><span class="dv">0</span><span class="op">];</span>main<span class="op">(</span>l<span class="op">){</span><span class="cf">for</span><span class="op">(;~</span>l<span class="op">;</span>O<span class="op">||</span>puts<span class="op">(</span>o<span class="op">))</span>O<span class="op">=(</span>O<span class="op">[</span>o<span class="op">]=~(</span>l<span class="op">=</span>getchar<span class="op">())?</span><span class="dv">4</span><span class="op">&lt;(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">&gt;&gt;</span><span class="dv">5</span><span class="op">)?</span>l<span class="op">:</span><span class="dv">46</span><span class="op">:</span><span class="dv">0</span><span class="op">)?-~</span>O<span class="op">&amp;</span>printf<span class="op">(</span><span class="st">&quot;</span><span class="sc">%02x</span><span class="st"> &quot;</span><span class="op">,</span>l<span class="op">)*</span><span class="dv">5</span><span class="op">:!</span>O<span class="op">;}</span></span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true" tabindex="-1"></a> <span class="co">// 109</span></span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true" tabindex="-1"></a> <span class="dt">char</span> O<span class="op">,</span>o<span class="op">[];</span>main<span class="op">(</span>l<span class="op">){</span><span class="cf">for</span><span class="op">(;~</span>l<span class="op">;</span>O<span class="op">||</span>puts<span class="op">(</span>o<span class="op">))</span>O<span class="op">=(</span>O<span class="op">[</span>o<span class="op">]=~(</span>l<span class="op">=</span>getchar<span class="op">())?</span><span class="dv">4</span><span class="op">&lt;(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">&gt;&gt;</span><span class="dv">5</span><span class="op">)?</span>l<span class="op">:</span><span class="dv">46</span><span class="op">:</span><span class="dv">0</span><span class="op">)?-~</span>O<span class="op">&amp;</span>printf<span class="op">(</span><span class="st">&quot;</span><span class="sc">%02x</span><span class="st"> &quot;</span><span class="op">,</span>l<span class="op">)*</span><span class="dv">5</span><span class="op">:!</span>O<span class="op">;}</span></span></code></pre></div>
<pre class="&lt;!---c--&gt;"><code> // 119
char O,o[20];main(l){for(;~(l=getchar());O||puts(o))o[O++]=isprint(l)?l:46,O&amp;=15,printf(&quot;%02x &quot;,l);O[o]=0;O&amp;&amp;puts(o);}
// 116
char O,o[20];main(l){for(;O++[o]=~(l=getchar())?4&lt;(4^l&gt;&gt;5)?l:46:0;(O&amp;=15)||puts(o))printf(&quot;%02x &quot;,l);O&gt;1&amp;&amp;puts(o);}
// 115
char O,o[20];main(l){for(;O[o]=~(l=getchar())?4&lt;(4^l&gt;&gt;5)?l:46:0;(O=-~O&amp;15)||puts(o))printf(&quot;%02x &quot;,l);O&amp;&amp;puts(o);}
// 113
char O,o[20];main(l){for(;~l;(O=~l?printf(&quot;%02x &quot;,l),-~O&amp;15:!O)||puts(o))O[o]=~(l=getchar())?4&lt;(4^l&gt;&gt;5)?l:46:0;}
// 112
char O,o[20];main(l){for(;~l;(O=~l?-~O&amp;printf(&quot;%02x &quot;,l)*5:!O)||puts(o))O[o]=~(l=getchar())?4&lt;(4^l&gt;&gt;5)?l:46:0;}
// 111
char O,o[20];main(l){for(;~l;O||puts(o))O=(O[o]=~(l=getchar())?4&lt;(4^l&gt;&gt;5)?l:46:0)?-~O&amp;printf(&quot;%02x &quot;,l)*5:!O;}
// 110
char O,o[0];main(l){for(;~l;O||puts(o))O=(O[o]=~(l=getchar())?4&lt;(4^l&gt;&gt;5)?l:46:0)?-~O&amp;printf(&quot;%02x &quot;,l)*5:!O;}
// 109
char O,o[];main(l){for(;~l;O||puts(o))O=(O[o]=~(l=getchar())?4&lt;(4^l&gt;&gt;5)?l:46:0)?-~O&amp;printf(&quot;%02x &quot;,l)*5:!O;}</code></pre>
<p>There are solutions without the ASCII sidebar that are significantly shorter.
These do not compete in the same category, since their output is materially different.
They are derived from the solutions above, but are still fascinating as concise utilities,
so here is their progression, for the curious:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="co">// 102</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> I<span class="op">;</span>O<span class="op">(</span>O<span class="op">){</span>putchar<span class="op">(</span>O<span class="op">+</span><span class="dv">48</span><span class="op">+</span><span class="dv">39</span><span class="op">*(</span><span class="dv">9</span><span class="op">&lt;</span>O<span class="op">));}</span>main<span class="op">(</span>l<span class="op">){</span><span class="cf">for</span><span class="op">(;~(</span>l<span class="op">=</span>getchar<span class="op">());</span>O<span class="op">(++</span>I<span class="op">&amp;</span><span class="dv">15</span><span class="op">?~</span><span class="dv">15</span><span class="op">:~</span><span class="dv">37</span><span class="op">))</span>O<span class="op">(</span>l<span class="op">&gt;&gt;</span><span class="dv">4</span><span class="op">),</span>O<span class="op">(</span>l<span class="op">&amp;</span><span class="dv">15</span><span class="op">);</span>O<span class="op">(-</span><span class="dv">38</span><span class="op">);}</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> <span class="co">// 80</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> O<span class="op">;</span>main<span class="op">(</span>l<span class="op">){</span><span class="cf">while</span><span class="op">(~(</span>l<span class="op">=</span>getchar<span class="op">()))</span>printf<span class="op">(</span><span class="st">&quot;</span><span class="sc">%02x%c</span><span class="st">&quot;</span><span class="op">,</span>l<span class="op">,++</span>O<span class="op">&amp;</span><span class="dv">15</span><span class="op">?</span><span class="dv">32</span><span class="op">:</span><span class="dv">10</span><span class="op">);</span>O<span class="op">&amp;</span><span class="dv">15</span><span class="op">&amp;&amp;</span>puts<span class="op">(</span><span class="st">&quot;&quot;</span><span class="op">);}</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a> <span class="co">// 78</span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a> O<span class="op">;</span>main<span class="op">(</span>l<span class="op">){</span><span class="cf">for</span><span class="op">(;~</span>l<span class="op">;(</span>O<span class="op">=~(</span>l<span class="op">=</span>getchar<span class="op">())?</span>printf<span class="op">(</span><span class="st">&quot;</span><span class="sc">%02x</span><span class="st"> &quot;</span><span class="op">,</span>l<span class="op">),-~</span>O<span class="op">&amp;</span><span class="dv">15</span><span class="op">:!</span>O<span class="op">)||</span>puts<span class="op">(</span><span class="st">&quot;&quot;</span><span class="op">));}</span></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a> <span class="co">// 77</span></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a> O<span class="op">;</span>main<span class="op">(</span>l<span class="op">){</span><span class="cf">for</span><span class="op">(;~</span>l<span class="op">;(</span>O<span class="op">=~(</span>l<span class="op">=</span>getchar<span class="op">())?-~</span>O<span class="op">&amp;</span>printf<span class="op">(</span><span class="st">&quot;</span><span class="sc">%02x</span><span class="st"> &quot;</span><span class="op">,</span>l<span class="op">)*</span><span class="dv">5</span><span class="op">:!</span>O<span class="op">)||</span>puts<span class="op">(</span><span class="st">&quot;&quot;</span><span class="op">));}</span></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a> <span class="co">// 76</span></span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a> O<span class="op">;</span>main<span class="op">(</span>l<span class="op">){</span><span class="cf">for</span><span class="op">(;~</span>l<span class="op">;</span>O<span class="op">||</span>puts<span class="op">(&amp;</span>O<span class="op">))</span>O<span class="op">=~(</span>l<span class="op">=</span>getchar<span class="op">())?-~</span>O<span class="op">&amp;</span>printf<span class="op">(</span><span class="st">&quot;</span><span class="sc">%02x</span><span class="st"> &quot;</span><span class="op">,</span>l<span class="op">)*</span><span class="dv">5</span><span class="op">:!</span>O<span class="op">;}</span></span></code></pre></div>
<pre class="&lt;!---c--&gt;"><code> // 102
I;O(O){putchar(O+48+39*(9&lt;O));}main(l){for(;~(l=getchar());O(++I&amp;15?~15:~37))O(l&gt;&gt;4),O(l&amp;15);O(-38);}
// 80
O;main(l){while(~(l=getchar()))printf(&quot;%02x%c&quot;,l,++O&amp;15?32:10);O&amp;15&amp;&amp;puts(&quot;&quot;);}
// 78
O;main(l){for(;~l;(O=~(l=getchar())?printf(&quot;%02x &quot;,l),-~O&amp;15:!O)||puts(&quot;&quot;));}
// 77
O;main(l){for(;~l;(O=~(l=getchar())?-~O&amp;printf(&quot;%02x &quot;,l)*5:!O)||puts(&quot;&quot;));}
// 76
O;main(l){for(;~l;O||puts(&amp;O))O=~(l=getchar())?-~O&amp;printf(&quot;%02x &quot;,l)*5:!O;}</code></pre>
<p>It is possible to reduce the size of each of these by one by eliding the trailing newline.
This was not reported above since the newline kept getting appended by processing software,
and it is more interesting to remove characters by changing code than by filtering:</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> tr <span class="at">-d</span> <span class="st">&#39;\012&#39;</span> <span class="op">&lt;</span> 109.c <span class="kw">|</span> <span class="fu">wc</span> <span class="at">-c</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">108</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> tr <span class="at">-d</span> <span class="st">&#39;\012&#39;</span> <span class="op">&lt;</span> 76.c <span class="kw">|</span> <span class="fu">wc</span> <span class="at">-c</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">75</span></span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> tr <span class="at">-d</span> <span class="st">&#39;\012&#39;</span> <span class="op">&lt;</span> 109.c <span class="kw">|</span> <span class="fu">cc</span> <span class="at">-o</span> 108 <span class="at">-xc</span> <span class="at">-</span></span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> verify 108</span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> $ tr -d &#39;\012&#39; &lt; 109.c | wc -c
108
$ tr -d &#39;\012&#39; &lt; 76.c | wc -c
75
$ tr -d &#39;\012&#39; &lt; 109.c | cc -o 108 -xc -
$ verify 108
$</code></pre>
<p>An obfuscated hex dump has been done before:
<a href="../../1986/bright/index.html">1986/bright</a> is similar in function,
but it uses more characters in just setting up its obfuscation than this entire
@@ -321,9 +321,9 @@ perhaps – the smallest, clean-compiling version using <code>clang</code> or <c
attempt, it will <em>not</em> work with the original Ritchie PDP-11 C compiler, since
the expression within the ternary remains too complex.</p>
<p>Try:</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> prog.c prog.alt.c</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> cat prog.c prog.alt.c</code></pre>
<p>or</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cmp</span> <span class="at">-b</span> prog.c prog.alt.c</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> cmp -b prog.c prog.alt.c</code></pre>
<p>to compare the differences (<code>diff</code> is not helpful on a one-liner).</p>
<!--
+13 -13
View File
@@ -1,26 +1,26 @@
## To build:
```sh
```<!---sh-->
make
```
## To use:
```sh
```<!---sh-->
./prog [-tcksri] < file.c
```
## Try:
```sh
```<!---sh-->
./try.sh
```
If you get really stuck, try:
```sh
```<!---sh-->
man ./tac.1
```
@@ -113,7 +113,7 @@ There is one (known) remaining problem with detection:
* Comments between preprocessor hash and keyword are not replaced with whitespace;
the following counts #include as two tokens, `#` and `include` (not as a reserved word):
```c
```<!---c-->
#/*this will not be counted*/include/*correctly*/<stdio.h>
```
@@ -128,14 +128,14 @@ counting words correctly absent `-k`.
`tac` was run over all 366 previous IOCCC winning entries:
```sh
```<!---sh-->
find ~/src/obc -type f -name \*.c | wc
```
The discrepancies found are documented and explained in the file
[discrepancies.html](discrepancies.html).
```sh
```<!---sh-->
find ~/src/obc -type f -a -name "*.c" | xargs ./spotcheck.sh ./prog | ./spotdiff.sh |
grep -v keep | diff -bw - discrep* | grep "[<>] cl "
```
@@ -181,14 +181,14 @@ For instance, here is a simple token counter, useful in finding repeated long to
frequency, or counting the references to identifiers, constants, or breadth of use of the
language:
```sh
```<!---sh-->
#!/usr/bin/env bash
cat $* | ./prog -t | sort | uniq -c | sort -k1nr
```
And here is a C keyword frequency counter:
```sh
```<!---sh-->
#!/usr/bin/env bash
function iskeyword {
awk 'BEGIN{f="c11";while(getline<f)k[$1]=0} {if($1 in k)k[$1]++}END{for(i in k)print k[i],i}'
@@ -222,7 +222,7 @@ simple code below is a serviceable obfuscated C de-obfuscator in a _scripting
language_. It really is this easy with `tac`:
```sh
```<!---sh-->
#!/usr/bin/env bash
script='
BEGIN {
@@ -342,7 +342,7 @@ which is neither complete (`#define`, `#ifndef`, `#undef` are missing
-- yes, Virginia knows about `#define` omitted on purpose),
nor correct (many more are added: `I`, `true`, `bool`, `compl`, ...):
```sh
```<!---sh-->
(sed -n '1p' c11; sed -n '2,$p' ioccc.kw.freq | sort) | comm -3 - c11
```
@@ -383,7 +383,7 @@ NB: This is *not* a portability concern, the one string holds only printable ASC
Thus:
```sh
```<!---sh-->
cc -ansi -Wall -trigraphs -Wno-trigraphs -Wno-parentheses -Wno-empty-body -Wno-char-subscripts -Wno-pointer-sign -DU=O -DW=\"keywords\" -o prog prog.c
```
@@ -403,7 +403,7 @@ are not recognised when written as `-rs` in prose).
Try:
```sh
```<!---sh-->
./manpage.sh tac
./manpage.sh -h
+64 -64
View File
@@ -141,13 +141,13 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="pp">[-</span><span class="ss">tcksri</span><span class="pp">]</span> <span class="op">&lt;</span> file.c</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog [-tcksri] &lt; file.c</code></pre>
<h2 id="try">Try:</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.sh</code></pre>
<p>If you get really stuck, try:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">man</span> ./tac.1</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> man ./tac.1</code></pre>
<h2 id="judges-remarks">Judges’ remarks:</h2>
<p>They say size isn’t everything, and in the case of IOCCC
<a href="../../2018/iocccsize.c">iocccsize.c</a> that is saying something!
@@ -228,17 +228,17 @@ quote consumes everything until the next quote</li>
<li>Comments between preprocessor hash and keyword are not replaced with whitespace;
the following counts #include as two tokens, <code>#</code> and <code>include</code> (not as a reserved word):</li>
</ul>
<div class="sourceCode" id="cb5"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">#</span><span class="er">/*this will not be counted*/include/*correctly*/&lt;stdio.h&gt;</span></span></code></pre></div>
<pre class="&lt;!---c--&gt;"><code> #/*this will not be counted*/include/*correctly*/&lt;stdio.h&gt;</code></pre>
<p>Fixing this properly hampers backwards compatibility in counting. This requires
eliding comments during the translation phases (ISO 5.1.1.2, phase 3), and yet still
counting words correctly absent <code>-k</code>.</p>
<h3 id="backwards-compatibility">Backwards Compatibility:</h3>
<p><code>tac</code> was run over all 366 previous IOCCC winning entries:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">find</span> ~/src/obc <span class="at">-type</span> f <span class="at">-name</span> <span class="dt">\*</span>.c <span class="kw">|</span> <span class="fu">wc</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> find ~/src/obc -type f -name \*.c | wc</code></pre>
<p>The discrepancies found are documented and explained in the file
<a href="discrepancies.html">discrepancies.html</a>.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">find</span> ~/src/obc <span class="at">-type</span> f <span class="at">-a</span> <span class="at">-name</span> <span class="st">&quot;*.c&quot;</span> <span class="kw">|</span> <span class="fu">xargs</span> ./spotcheck.sh ./prog <span class="kw">|</span> <span class="ex">./spotdiff.sh</span> <span class="kw">|</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">grep</span> <span class="at">-v</span> keep <span class="kw">|</span> <span class="fu">diff</span> <span class="at">-bw</span> <span class="at">-</span> discrep<span class="pp">*</span> <span class="kw">|</span> <span class="fu">grep</span> <span class="st">&quot;[&lt;&gt;] cl &quot;</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> find ~/src/obc -type f -a -name &quot;*.c&quot; | xargs ./spotcheck.sh ./prog | ./spotdiff.sh |
grep -v keep | diff -bw - discrep* | grep &quot;[&lt;&gt;] cl &quot;</code></pre>
<p>In summary, there are only 6 unique entries out of 366 that have any variation
in Rule 2 counts; in all cases, the differences are due to bugs within
<code>iocccsize</code>, described in detail in the file
@@ -273,14 +273,14 @@ This feature enables interesting analyses of C (and C++) code that’s hard to g
<p>For instance, here is a simple token counter, useful in finding repeated long tokens, or operator
frequency, or counting the references to identifiers, constants, or breadth of use of the
language:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="co">#!/usr/bin/env bash</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> <span class="va">$*</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-t</span> <span class="kw">|</span> <span class="fu">sort</span> <span class="kw">|</span> <span class="fu">uniq</span> <span class="at">-c</span> <span class="kw">|</span> <span class="fu">sort</span> <span class="at">-k1nr</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> #!/usr/bin/env bash
cat $* | ./prog -t | sort | uniq -c | sort -k1nr</code></pre>
<p>And here is a C keyword frequency counter:</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="co">#!/usr/bin/env bash</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">function</span><span class="fu"> iskeyword</span> <span class="kw">{</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">awk</span> <span class="st">&#39;BEGIN{f=&quot;c11&quot;;while(getline&lt;f)k[$1]=0} {if($1 in k)k[$1]++}END{for(i in k)print k[i],i}&#39;</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a> <span class="kw">}</span></span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> <span class="va">$*</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-t</span> <span class="kw">|</span> <span class="ex">iskeyword</span> <span class="kw">|</span> <span class="fu">sort</span> <span class="at">-k1nr</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> #!/usr/bin/env bash
function iskeyword {
awk &#39;BEGIN{f=&quot;c11&quot;;while(getline&lt;f)k[$1]=0} {if($1 in k)k[$1]++}END{for(i in k)print k[i],i}&#39;
}
cat $* | ./prog -t | iskeyword | sort -k1nr</code></pre>
<p>This script was used to “optimize” the reserved word order so the most frequent IOCCC
winning entry keywords are checked first.</p>
<p>An interesting aside: as might be expected, obfuscation has changed the frequency of
@@ -299,47 +299,47 @@ handful of simple rules (and another use of the external keyword file). A more
refined version of this is included in the file <a href="unob.sh">unob.sh</a>, but the
simple code below is a serviceable obfuscated C de-obfuscator in a <em>scripting
language</em>. It really is this easy with <code>tac</code>:</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> <span class="co">#!/usr/bin/env bash</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="va">script</span><span class="op">=</span><span class="st">&#39;</span></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="st"> BEGIN {</span></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a><span class="st"> last=nl=&quot;\n&quot;;</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a><span class="st"> f=&quot;c11&quot;; while(getline &lt;f &gt; 0) kw[$0]++; close(f);</span></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a><span class="st"> }</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a><span class="st"> function iskw(a) { return a in kw }</span></span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a><span class="st"> function indent(a) { return sprintf(&quot;%*s&quot;, n*3, &quot; &quot;) }</span></span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a><span class="st"> function newline() { if (!infor &amp;&amp; last != nl) printf last=nl; }</span></span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a><span class="st"> function show(a) {</span></span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a><span class="st"> if (last==nl) printf &quot;%s&quot;, indent()</span></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a><span class="st"> printf &quot;%s%s&quot;, space(), a</span></span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a><span class="st"> last=a</span></span>
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a><span class="st"> }</span></span>
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a><span class="st"> function space() {</span></span>
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true" tabindex="-1"></a><span class="st"> return iskw(last) ||</span></span>
<span id="cb11-18"><a href="#cb11-18" aria-hidden="true" tabindex="-1"></a><span class="st"> (last ~ /[A-Za-z0-9_+-\/%^[&amp;\]\)=:&lt;&gt;;]$/ &amp;&amp; $0 !~ /[:;()\[\],]/) ? &quot; &quot; : &quot;&quot;</span></span>
<span id="cb11-19"><a href="#cb11-19" aria-hidden="true" tabindex="-1"></a><span class="st"> }</span></span>
<span id="cb11-20"><a href="#cb11-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-21"><a href="#cb11-21" aria-hidden="true" tabindex="-1"></a><span class="st"> /^\(/ { ++paren }</span></span>
<span id="cb11-22"><a href="#cb11-22" aria-hidden="true" tabindex="-1"></a><span class="st"> /^\)/ { --paren }</span></span>
<span id="cb11-23"><a href="#cb11-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-24"><a href="#cb11-24" aria-hidden="true" tabindex="-1"></a><span class="st"> /^for/ { newline(); infor=1 }</span></span>
<span id="cb11-25"><a href="#cb11-25" aria-hidden="true" tabindex="-1"></a><span class="st"> infor &amp;&amp; /^;/ { ++infor; show($0 &quot; &quot;); next }</span></span>
<span id="cb11-26"><a href="#cb11-26" aria-hidden="true" tabindex="-1"></a><span class="st"> infor==1 &amp;&amp; /^:/ { ++infor }</span></span>
<span id="cb11-27"><a href="#cb11-27" aria-hidden="true" tabindex="-1"></a><span class="st"> infor&gt;1 &amp;&amp; paren==0 { infor=0 }</span></span>
<span id="cb11-28"><a href="#cb11-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-29"><a href="#cb11-29" aria-hidden="true" tabindex="-1"></a><span class="st"> /^\?/ { tern++; n++; newline(); show($0 &quot; &quot;); next }</span></span>
<span id="cb11-30"><a href="#cb11-30" aria-hidden="true" tabindex="-1"></a><span class="st"> tern &amp;&amp; /^:/ { newline(); show($0); --tern; --n; next }</span></span>
<span id="cb11-31"><a href="#cb11-31" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-32"><a href="#cb11-32" aria-hidden="true" tabindex="-1"></a><span class="st"> /^#/ { newline(); show($0); newline(); next }</span></span>
<span id="cb11-33"><a href="#cb11-33" aria-hidden="true" tabindex="-1"></a><span class="st"> /^;/ { show($0); newline(); next }</span></span>
<span id="cb11-34"><a href="#cb11-34" aria-hidden="true" tabindex="-1"></a><span class="st"> /^{/ { show($0); ++n; newline(); next }</span></span>
<span id="cb11-35"><a href="#cb11-35" aria-hidden="true" tabindex="-1"></a><span class="st"> /^}/ { n--; newline(); show($0); newline(); next }</span></span>
<span id="cb11-36"><a href="#cb11-36" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-37"><a href="#cb11-37" aria-hidden="true" tabindex="-1"></a><span class="st"> { show($0) }</span></span>
<span id="cb11-38"><a href="#cb11-38" aria-hidden="true" tabindex="-1"></a><span class="st"> &#39;</span></span>
<span id="cb11-39"><a href="#cb11-39" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> <span class="va">$*</span> <span class="kw">|</span> <span class="fu">sed</span> <span class="st">&#39;s/#include/##include/&#39;</span> <span class="kw">|</span> <span class="fu">cpp</span> <span class="at">-E</span> <span class="at">-trigraphs</span> <span class="kw">|</span></span>
<span id="cb11-40"><a href="#cb11-40" aria-hidden="true" tabindex="-1"></a> <span class="fu">sed</span> <span class="st">&#39;s/^# .*$//&#39;</span> <span class="kw">|</span> <span class="fu">sed</span> <span class="st">&#39;s/^#//&#39;</span> <span class="kw">|</span></span>
<span id="cb11-41"><a href="#cb11-41" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="at">-t</span> <span class="kw">|</span> <span class="fu">awk</span> <span class="st">&quot;</span><span class="va">$script</span><span class="st">&quot;</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> #!/usr/bin/env bash
script=&#39;
BEGIN {
last=nl=&quot;\n&quot;;
f=&quot;c11&quot;; while(getline &lt;f &gt; 0) kw[$0]++; close(f);
}
function iskw(a) { return a in kw }
function indent(a) { return sprintf(&quot;%*s&quot;, n*3, &quot; &quot;) }
function newline() { if (!infor &amp;&amp; last != nl) printf last=nl; }
function show(a) {
if (last==nl) printf &quot;%s&quot;, indent()
printf &quot;%s%s&quot;, space(), a
last=a
}
function space() {
return iskw(last) ||
(last ~ /[A-Za-z0-9_+-\/%^[&amp;\]\)=:&lt;&gt;;]$/ &amp;&amp; $0 !~ /[:;()\[\],]/) ? &quot; &quot; : &quot;&quot;
}
/^\(/ { ++paren }
/^\)/ { --paren }
/^for/ { newline(); infor=1 }
infor &amp;&amp; /^;/ { ++infor; show($0 &quot; &quot;); next }
infor==1 &amp;&amp; /^:/ { ++infor }
infor&gt;1 &amp;&amp; paren==0 { infor=0 }
/^\?/ { tern++; n++; newline(); show($0 &quot; &quot;); next }
tern &amp;&amp; /^:/ { newline(); show($0); --tern; --n; next }
/^#/ { newline(); show($0); newline(); next }
/^;/ { show($0); newline(); next }
/^{/ { show($0); ++n; newline(); next }
/^}/ { n--; newline(); show($0); newline(); next }
{ show($0) }
&#39;
cat $* | sed &#39;s/#include/##include/&#39; | cpp -E -trigraphs |
sed &#39;s/^# .*$//&#39; | sed &#39;s/^#//&#39; |
./prog -t | awk &quot;$script&quot;</code></pre>
<h3 id="on-the-question-of-obfuscation">On the question of obfuscation:</h3>
<ul>
<li><p>I assume you noticed the <a href="https://www.youtube.com/watch?v=fUspLVStPbk&amp;start=53" title="Meaning of Life">braces</a>?</p>
@@ -401,7 +401,7 @@ the IOJCC trash can.</p>
which is neither complete (<code>#define</code>, <code>#ifndef</code>, <code>#undef</code> are missing
– yes, Virginia knows about <code>#define</code> omitted on purpose),
nor correct (many more are added: <code>I</code>, <code>true</code>, <code>bool</code>, <code>compl</code>, …):</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="kw">(</span><span class="fu">sed</span> <span class="at">-n</span> <span class="st">&#39;1p&#39;</span> c11<span class="kw">;</span> <span class="fu">sed</span> <span class="at">-n</span> <span class="st">&#39;2,$p&#39;</span> ioccc.kw.freq <span class="kw">|</span> <span class="fu">sort</span><span class="kw">)</span> <span class="kw">|</span> <span class="fu">comm</span> <span class="at">-3</span> <span class="at">-</span> c11</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> (sed -n &#39;1p&#39; c11; sed -n &#39;2,$p&#39; ioccc.kw.freq | sort) | comm -3 - c11</code></pre>
<p>That is an obfuscated way to say “diff”. But it also more clearly shows the, um, diffs.</p>
<p>The usage string is similarly externalized, providing a better usability string than
the limits would otherwise allow. If this is considered bending the rules too far,
@@ -429,7 +429,7 @@ for obfuscation. Thus <code>-trigraphs -Wno-trigraphs</code> (which is also humo
<p>The code uses <code>unsigned char</code>s, but C strings are <code>signed</code>. Thus <code>-Wno-pointer-sign</code>.
NB: This is <em>not</em> a portability concern, the one string holds only printable ASCII characters.</p>
<p>Thus:</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> <span class="at">-ansi</span> <span class="at">-Wall</span> <span class="at">-trigraphs</span> <span class="at">-Wno-trigraphs</span> <span class="at">-Wno-parentheses</span> <span class="at">-Wno-empty-body</span> <span class="at">-Wno-char-subscripts</span> <span class="at">-Wno-pointer-sign</span> <span class="at">-DU</span><span class="op">=</span>O <span class="at">-DW</span><span class="op">=</span><span class="dt">\&quot;</span>keywords<span class="dt">\&quot;</span> <span class="at">-o</span> prog prog.c</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> cc -ansi -Wall -trigraphs -Wno-trigraphs -Wno-parentheses -Wno-empty-body -Wno-char-subscripts -Wno-pointer-sign -DU=O -DW=\&quot;keywords\&quot; -o prog prog.c</code></pre>
<h3 id="coda">Coda:</h3>
<p><a href="../../authors.html#Cody_Boone_Ferguson">Cody Boone Ferguson</a> was relentless in his pursuit of bugs.
Thanks to his reports, the version of <a href="unob.sh">unob.sh</a> is stronger,
@@ -442,12 +442,12 @@ works well on most inputs, but tends to need some raw nroff for more fancy
constructions, such as combined arguments (e.g. the <code>-r</code> and <code>-s</code> arguments to tac
are not recognised when written as <code>-rs</code> in prose).</p>
<p>Try:</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./manpage.sh</span> tac</span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./manpage.sh</span> <span class="at">-h</span></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">./manpage.sh</span> <span class="at">-h</span> <span class="kw">|</span> <span class="ex">./manpage.sh</span></span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">./manpage.sh</span> <span class="at">-h</span> <span class="kw">|</span> <span class="ex">./manpage.sh</span> <span class="at">-R</span> <span class="kw">|</span> <span class="fu">less</span></span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">./manpage.sh</span> <span class="at">-h</span> <span class="kw">|</span> <span class="ex">./manpage.sh</span> <span class="at">-P</span> <span class="kw">|</span> <span class="fu">lpr</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./manpage.sh tac
./manpage.sh -h
./manpage.sh -h | ./manpage.sh
./manpage.sh -h | ./manpage.sh -R | less
./manpage.sh -h | ./manpage.sh -P | lpr</code></pre>
<p>NOTE: in 2023 the <code>tac.man</code> was updated to proper man format and renamed
<a href="tac.1">tac.1</a>.</p>
<!--
+5 -5
View File
@@ -1,6 +1,6 @@
## To build:
```sh
```<!---sh-->
make
```
@@ -11,14 +11,14 @@ below for more details.
## To use:
```sh
```<!---sh-->
./prog < text
```
## Try:
```sh
```<!---sh-->
./try.sh
```
@@ -32,7 +32,7 @@ useful bug fix.
### Alternate build:
```sh
```<!---sh-->
make alt
```
@@ -44,7 +44,7 @@ Use `prog.alt` as you would `prog` above.
### Alternate try:
```sh
```<!---sh-->
./try.alt.sh
```
+5 -5
View File
@@ -141,24 +141,24 @@ Location: <a href="../../location.html#PL">PL</a> - <em>Republic of Poland</em>
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<p>There is an alternate version that lacks a useful bug fix. See <a href="#alternate-code">Alternate
code</a> and the author’s remarks (<a href="#remarks">remarks section</a>)
below for more details.</p>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op">&lt;</span> text</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog &lt; text</code></pre>
<h2 id="try">Try:</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.sh</code></pre>
<h2 id="alternate-code">Alternate code:</h2>
<p>An alternate version of this entry, <a href="prog.alt.c">prog.alt.c</a>, is provided. As
mentioned in the author’s <a href="#remarks">remarks</a>, the alternate version lacks a
useful bug fix.</p>
<h3 id="alternate-build">Alternate build:</h3>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> alt</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make alt</code></pre>
<h3 id="alternate-use">Alternate use:</h3>
<p>Use <code>prog.alt</code> as you would <code>prog</code> above.</p>
<h3 id="alternate-try">Alternate try:</h3>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.alt.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.alt.sh</code></pre>
<p>Do you spot the fix by running both <a href="try.sh">try.sh</a> and
<a href="try.alt.sh">try.alt.sh</a>?</p>
<h2 id="judges-remarks">Judges’ remarks:</h2>
+6 -6
View File
@@ -1,13 +1,13 @@
## To build:
```sh
```<!---sh-->
make
```
## To use:
```sh
```<!---sh-->
./prog < textfile > output.gif
```
@@ -16,7 +16,7 @@
To see the input files and feed them to the program, redirecting to GIF files:
```sh
```<!---sh-->
./try.sh
```
@@ -40,7 +40,7 @@ least 2MiB of memory to run in.
This program generates an animated GIF from a plain text. Run:
```sh
```<!---sh-->
cc -o prog prog.c
./prog < invisible.txt > invisible.gif
```
@@ -51,14 +51,14 @@ letters that leave the mark and ones that do not?
Other examples:
```sh
```<!---sh-->
./prog < golem.txt > golem.gif
./prog < smily.txt > smily.gif
```
The program itself has a hidden message.
```sh
```<!---sh-->
./prog < prog.c > prog.gif
```
+8 -8
View File
@@ -141,12 +141,12 @@ Location: <a href="../../location.html#JP">JP</a> - <em>Japan</em></li>
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op">&lt;</span> textfile <span class="op">&gt;</span> output.gif</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog &lt; textfile &gt; output.gif</code></pre>
<h2 id="try">Try:</h2>
<p>To see the input files and feed them to the program, redirecting to GIF files:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.sh</code></pre>
<h2 id="judges-remarks">Judges’ remarks:</h2>
<p>To get the best experience, use a GIF viewer that can handle animated GIFs.
With macOS you can use Safari using <code>open -a Safari smily.gif</code>.</p>
@@ -158,16 +158,16 @@ how does it know which characters are closed?</p>
least 2MiB of memory to run in.</p>
<h2 id="authors-remarks">Author’s remarks:</h2>
<p>This program generates an animated GIF from a plain text. Run:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> <span class="at">-o</span> prog prog.c</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op">&lt;</span> invisible.txt <span class="op">&gt;</span> invisible.gif</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> cc -o prog prog.c
./prog &lt; invisible.txt &gt; invisible.gif</code></pre>
<p>Open <code>invisible.gif</code> with a GIF viewer that can show animated GIFs and then wait
a minute. You will see a hidden message. Can you tell the difference between
letters that leave the mark and ones that do not?</p>
<p>Other examples:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op">&lt;</span> golem.txt <span class="op">&gt;</span> golem.gif</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op">&lt;</span> smily.txt <span class="op">&gt;</span> smily.gif</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog &lt; golem.txt &gt; golem.gif
./prog &lt; smily.txt &gt; smily.gif</code></pre>
<p>The program itself has a hidden message.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op">&lt;</span> prog.c <span class="op">&gt;</span> prog.gif</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog &lt; prog.c &gt; prog.gif</code></pre>
<!--
Copyright © 1984-2024 by Landon Curt Noll. All Rights Reserved.
+3 -3
View File
@@ -1,20 +1,20 @@
## To build:
```sh
```<!---sh-->
make
```
## To use:
```sh
```<!---sh-->
./prog
```
## Try:
```sh
```<!---sh-->
./try.sh
```
+3 -3
View File
@@ -141,11 +141,11 @@ Location: <a href="../../location.html#JP">JP</a> - <em>Japan</em></li>
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog</code></pre>
<h2 id="try">Try:</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.sh</code></pre>
<p>NOTE: to interrupt the loops send intr (typically ctrl-C).</p>
<h2 id="judges-remarks">Judges’ remarks:</h2>
<p>And now for something completely different: A program whose metabolic
+38 -38
View File
@@ -1,6 +1,6 @@
## To build:
```sh
```<!---sh-->
make
```
@@ -10,14 +10,14 @@ monkey Eric. See [Alternate code](#alternate-code) below.
## To use:
```sh
```<!---sh-->
./weasel
```
## Try:
```sh
```<!---sh-->
./try.sh
# For those who believe in '"intelligent" design' or want to see how easy it is
@@ -47,7 +47,7 @@ about this under the [keyboards](#keyboards) section, briefly referred to in the
### Alternate build:
```sh
```<!---sh-->
make alt
```
@@ -59,7 +59,7 @@ Use `weasel.alt` as you would `weasel` above.
### Alternate try:
```sh
```<!---sh-->
./try.alt.sh
# For those who believe in '"intelligent" design' or want to see how easy it is
@@ -80,7 +80,7 @@ detail in the [S, M and N Constants](#constants) section. The script above will
make use of some of these.
```sh
```<!---sh-->
./try.alt.sh
```
@@ -107,7 +107,7 @@ while using more Cenozoic minded code migration, read [rpm.html](rpm.html).
If you find yourself in an evolutionary dead end, try:
```sh
```<!---sh-->
man ./weasel.1
```
@@ -139,7 +139,7 @@ texts. To resolve this I think the best way is referencing the judges' remarks:
if you want a quick rundown of the entry try what they suggest and view the man
page (it explains all the options and describes the program briefly):
```sh
```<!---sh-->
man ./weasel.man
```
@@ -444,7 +444,7 @@ has more than one word (that is it contains spaces) or anything else interpreted
specially by your shell e.g. parentheses. For instance if you just want to find
`METHINKS` you could do one of:
```sh
```<!---sh-->
./weasel METHINKS
./weasel "METHINKS"
./weasel 'METHINKS'
@@ -452,14 +452,14 @@ specially by your shell e.g. parentheses. For instance if you just want to find
If you wanted `YOU ARE A MONKEY`:
```sh
```<!---sh-->
./weasel "YOU ARE A MONKEY"
./weasel 'YOU ARE A MONKEY'
```
If you do one of:
```sh
```<!---sh-->
./weasel "METHINKS IT IS A" "MONKEY"
./weasel METHINKS IT IS A MONKEY
```
@@ -472,7 +472,7 @@ If you actually do want to search for a string starting with a `-` you must
disable further parsing of options by using the `-` option itself; for
example if you were to do any of:
```sh
```<!---sh-->
./weasel -q- -- -test
./weasel -q- -test
./weasel -q -- -test
@@ -480,7 +480,7 @@ example if you were to do any of:
The target string will be: `-TEST`. This means though that here:
```sh
```<!---sh-->
./weasel -q -- -test -r5
```
@@ -498,7 +498,7 @@ are equivalent:
As for the caveat I referenced what does the following do?
```sh
```<!---sh-->
./weasel -qr 5
```
@@ -510,7 +510,7 @@ note on the parsing of the `-` option; if the program is currently parsing
the other options are in the command line it might still parse the options. Thus
you have:
```sh
```<!---sh-->
$ ./weasel -qr-r5
quiet output
mutation rate out of range
@@ -522,14 +522,14 @@ you have:
Similarly this would set quiet output, then an invalid mutation rate and then a
mutation rate of 5:
```sh
```<!---sh-->
./weasel --qrr5
```
If you were instead to do one of (for example):
```sh
```<!---sh-->
./weasel -q -- -r
./weasel -q -q- -r
```
@@ -568,7 +568,7 @@ requested? There are at least two ways to go about it: I took the monkey safe
('fool safe') method; *if you explicitly request monkey mode you cannot disable
it in the same invocation of `weasel`!
```sh
```<!---sh-->
$ ./weasel -qr101r5r101r1r test
quiet output
mutation rate out of range
@@ -633,7 +633,7 @@ in monkey mode.
Another example:
```sh
```<!---sh-->
$ ./weasel -q -r101 test -r5
quiet output
mutation rate out of range
@@ -649,7 +649,7 @@ which means that it'll use the genetic algorithm.
One more example of monkey mode:
```sh
```<!---sh-->
$ ./weasel -q -mr101 test -r5
quiet output
mutation rate out of range
@@ -771,13 +771,13 @@ with.
Try:
```sh
```<!---sh-->
make test
```
This will essentially make sure the program is compiled and then do:
```sh
```<!---sh-->
chmod +x test.sh
./test.sh
```
@@ -793,7 +793,7 @@ processed).
You can pass additional options directly to the script but remember that it
stops when there are no more strings in the file - so if you try:
```sh
```<!---sh-->
./test.sh -q test
```
@@ -825,7 +825,7 @@ program prints an error message and then exits (returning 1). But since the
keyboard doesn't have `'\n'` if you were to type a `'` and send a
`'\n'` before the closing `'` you might see something like:
```sh
```<!---sh-->
$ ./weasel '!!
> '
@@ -858,7 +858,7 @@ as well as some C keywords.
2. The way `main()` is declared is:
```c
```<!---c-->
/* Special C main() handler (encapsulation): */
#define r(main) main
r(k main(k a, E **V)) {
@@ -952,7 +952,7 @@ somewhere!).
The Makefile simplifies how to reconfigure this value with the variable
`MAX_SIZE`:
```sh
```<!---sh-->
make clobber MAX_SIZE=55 all
```
@@ -965,7 +965,7 @@ number attempts without waiting for a very long time.
The Makefile simplifies how to reconfigure this value with the variable
`MAX_ATTEMPTS`:
```sh
```<!---sh-->
make clobber MAX_ATTEMPTS=100 all
```
@@ -982,7 +982,7 @@ and the larger the values the more memory it'll require.
The Makefile simplifies how to reconfigure this value with the variable
`OFFSPRING`:
```sh
```<!---sh-->
make clobber OFFSPRING=55 all
```
@@ -993,7 +993,7 @@ Skip to [Portability](#portability).
The following options **must always be passed to the compiler:**
```sh
```<!---sh-->
-DQ='typedef' -D'g(o)'='goto o;' -D'w(x)'="x:" -D'H(main)'='r(main)'
```
@@ -1003,13 +1003,13 @@ which running `make` will always do.
If you want to increase the number of offspring to `50` (`N`) and the size of the
chromosome to `75` (`S`) you would do:
```sh
```<!---sh-->
make clobber OFFSPRING=50 MAX_SIZE=75 everything
```
If you wanted to change `N` to `3`:
```sh
```<!---sh-->
make clobber OFFSPRING=3 everything
```
@@ -1020,7 +1020,7 @@ result. Remember too that `S` (`MAX_SIZE`) cannot be less than `38`. Both `S` an
If you wanted to change the maximum number attempts to 100 you could do:
```sh
```<!---sh-->
make clobber MAX_ATTEMPTS=100 everything
```
@@ -1038,7 +1038,7 @@ Originally I tested it on the below systems.
#### Fedora 26:
```sh
```<!---sh-->
$ clang --version|head -n1
clang version 4.0.1 (tags/RELEASE_401/final)
$ gcc --version|head -n1
@@ -1051,7 +1051,7 @@ Originally I tested it on the below systems.
#### CentOS Linux release 7.4.1708 (Core)
```sh
```<!---sh-->
$ clang --version|head -n1
clang version 3.4.2 (tags/RELEASE_34/dot2-final)
$ gcc --version|head -n1
@@ -1064,7 +1064,7 @@ Originally I tested it on the below systems.
#### Fedora 27:
```sh
```<!---sh-->
$ clang --version|head -n1
clang version 5.0.1 (tags/RELEASE_501/final)
$ gcc --version|head -n1
@@ -1080,7 +1080,7 @@ Originally I tested it on the below systems.
System Version: macOS 10.13.4 (17E199)
Kernel Version: Darwin 17.5.0
```sh
```<!---sh-->
$ gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.1.0 (clang-902.0.39.1)
@@ -1209,7 +1209,7 @@ When we found others were actually trying to programs with A, we quickly added
additional cryptic features and evolved into B, BCPL, and finally C. We stopped
when we got a clean compile on the following syntax:
```c
```<!---c-->
for(;P("\n"),R=;P("|"))for(e=C;e=P("_"+(*u++/
8)%2))P("|"+(*u/4)%2);
```
@@ -1252,7 +1252,7 @@ is a lack of common sense but since he was part of its creation I don't think
it's a bad thing; **on the contrary it makes all of us C programmers even more
talented! :)** I do wonder if he tested that bit of C code though:
```c
```<!---c-->
for(;P("\n"),R=;P("|"))for(e=C;e=P("_"+(*u++/
8)%2))P("|"+(*u/4)%2);
```
+122 -122
View File
@@ -141,21 +141,21 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<p>The author provided an alternate version which has a simpler keyboard for the
monkey Eric. See <a href="#alternate-code">Alternate code</a> below.</p>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./weasel</code></pre>
<h2 id="try">Try:</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="co"># For those who believe in &#39;&quot;intelligent&quot; design&#39; or want to see how easy it is</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="co"># to prove evolution is a proven fact:</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">./id.sh</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="co"># For those who want to see if Eric the monkey can type the word &#39;words&#39; before</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a> <span class="co"># falling asleep or giving up:</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">./monkey-words.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.sh
# For those who believe in &#39;&quot;intelligent&quot; design&#39; or want to see how easy it is
# to prove evolution is a proven fact:
./id.sh
# For those who want to see if Eric the monkey can type the word &#39;words&#39; before
# falling asleep or giving up:
./monkey-words.sh</code></pre>
<p>NOTE: the <a href="try.sh">try.sh</a> script will run the other two scripts but if the
first one, <a href="id.sh">id.sh</a> is terminated early in the try script, the second one,
<a href="monkey-words.sh">monkey-words.sh</a> will not be run.</p>
@@ -167,26 +167,26 @@ make use of some of these.</p>
about this under the <a href="#keyboards">keyboards</a> section, briefly referred to in the
<a href="#what">what it is</a> section.</p>
<h3 id="alternate-build">Alternate build:</h3>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> alt</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make alt</code></pre>
<h3 id="alternate-use">Alternate use:</h3>
<p>Use <code>weasel.alt</code> as you would <code>weasel</code> above.</p>
<h3 id="alternate-try">Alternate try:</h3>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.alt.sh</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <span class="co"># For those who believe in &#39;&quot;intelligent&quot; design&#39; or want to see how easy it is</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> <span class="co"># to prove evolution is a proven fact:</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">./id.alt.sh</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> <span class="co"># For those who want to see if Eric the monkey can type the word &#39;words&#39; before</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> <span class="co"># falling asleep or giving up:</span></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">./monkey-words.alt.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.alt.sh
# For those who believe in &#39;&quot;intelligent&quot; design&#39; or want to see how easy it is
# to prove evolution is a proven fact:
./id.alt.sh
# For those who want to see if Eric the monkey can type the word &#39;words&#39; before
# falling asleep or giving up:
./monkey-words.alt.sh</code></pre>
<p>NOTE: the <a href="try.alt.sh">try.alt.sh</a> script will run the other two scripts but if the
first one, <a href="id.alt.sh">id.alt.sh</a> is terminated early in the try script, the second one,
<a href="monkey-words.alt.sh">monkey-words.alt.sh</a> will not be run.</p>
<p>You can reconfigure certain values. These are described by the author in more
detail in the <a href="#constants">S, M and N Constants</a> section. The script above will
make use of some of these.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.alt.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.alt.sh</code></pre>
<p>You can reconfigure certain values. These are described by the author in more
detail in the <a href="#constants">S, M and N Constants</a> section. The script above will
make use of some of these.</p>
@@ -203,7 +203,7 @@ from the phylogenetic tree of life.</p>
<p>If you wish your computer to maintain one branch in the Cretaceous C code era,
while using more Cenozoic minded code migration, read <a href="rpm.html">rpm.html</a>.</p>
<p>If you find yourself in an evolutionary dead end, try:</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">man</span> ./weasel.1</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> man ./weasel.1</code></pre>
<h2 id="authors-remarks">Author’s remarks:</h2>
<ol start="0" type="1">
<li>Preface</li>
@@ -228,7 +228,7 @@ didn’t want to reveal as much publicly and many people don’t like to read lo
texts. To resolve this I think the best way is referencing the judges’ remarks:
if you want a quick rundown of the entry try what they suggest and view the man
page (it explains all the options and describes the program briefly):</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">man</span> ./weasel.man</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> man ./weasel.man</code></pre>
<p>If that isn’t sufficient <strong>I would recommend reading this section</strong> <em>(and
possibly the next)</em> where I attempt to give a brief explanation of the sections
to make reading it easier and faster. In addition I want to point out a few
@@ -461,26 +461,26 @@ it must be a single parameter which means you’ll need to quote the string if i
has more than one word (that is it contains spaces) or anything else interpreted
specially by your shell e.g. parentheses. For instance if you just want to find
<code>METHINKS</code> you could do one of:</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> METHINKS</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> <span class="st">&quot;METHINKS&quot;</span></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> <span class="st">&#39;METHINKS&#39;</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./weasel METHINKS
./weasel &quot;METHINKS&quot;
./weasel &#39;METHINKS&#39;</code></pre>
<p>If you wanted <code>YOU ARE A MONKEY</code>:</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> <span class="st">&quot;YOU ARE A MONKEY&quot;</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> <span class="st">&#39;YOU ARE A MONKEY&#39;</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./weasel &quot;YOU ARE A MONKEY&quot;
./weasel &#39;YOU ARE A MONKEY&#39;</code></pre>
<p>If you do one of:</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> <span class="st">&quot;METHINKS IT IS A&quot;</span> <span class="st">&quot;MONKEY&quot;</span></span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> METHINKS IT IS A MONKEY</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./weasel &quot;METHINKS IT IS A&quot; &quot;MONKEY&quot;
./weasel METHINKS IT IS A MONKEY</code></pre>
<p>It will search for <code>MONKEY</code> in both cases; in other words it’s the last one.
If the string is too long given the value of <code>S</code> (see<br />
<strong><a href="#build">How to build</a></strong>) it will be truncated.</p>
<p>If you actually do want to search for a string starting with a <code>-</code> you must
disable further parsing of options by using the <code>-</code> option itself; for
example if you were to do any of:</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> <span class="at">-q-</span> <span class="at">--</span> <span class="at">-test</span></span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> <span class="at">-q-</span> <span class="at">-test</span></span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> <span class="at">-q</span> <span class="at">--</span> <span class="at">-test</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./weasel -q- -- -test
./weasel -q- -test
./weasel -q -- -test</code></pre>
<p>The target string will be: <code>-TEST</code>. This means though that here:</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> <span class="at">-q</span> <span class="at">--</span> <span class="at">-test</span> <span class="at">-r5</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./weasel -q -- -test -r5</code></pre>
<p>The string to be searched would actually be <code>-r5</code> and the mutation rate
will remain the default because after the <code>-</code> option is seen it will no
longer parse additional options: only target strings if anything left on the
@@ -490,7 +490,7 @@ are equivalent:</p>
<pre><code> -q-\
-q --</code></pre>
<p>As for the caveat I referenced what does the following do?</p>
<div class="sourceCode" id="cb22"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> <span class="at">-qr</span> 5</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./weasel -qr 5</code></pre>
<p>In fact it will set quiet output and set the target string to be ‘5’. So the
mutation rate will be out of range, thus enabling that Easter egg, but it will
likely come to an answer fairly quickly because it’s just a single character. A
@@ -498,18 +498,18 @@ note on the parsing of the <code>-</code> option; if the program is currently pa
<code>argv[N]</code>, for example, and it encounters a <code>--</code> then depending on where
the other options are in the command line it might still parse the options. Thus
you have:</p>
<div class="sourceCode" id="cb23"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./weasel <span class="at">-qr-r5</span></span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">quiet</span> output</span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">mutation</span> rate out of range</span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">target</span> <span class="st">&#39;METHINKS IT IS LIKE A WEASEL&#39;</span></span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">mutation</span> rate 5</span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">Generation</span> 440 Offspring 20: METHINKS IT IS LIKE A WEASEL</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> $ ./weasel -qr-r5
quiet output
mutation rate out of range
target &#39;METHINKS IT IS LIKE A WEASEL&#39;
mutation rate 5
Generation 440 Offspring 20: METHINKS IT IS LIKE A WEASEL</code></pre>
<p>Similarly this would set quiet output, then an invalid mutation rate and then a
mutation rate of 5:</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> <span class="at">--qrr5</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./weasel --qrr5</code></pre>
<p>If you were instead to do one of (for example):</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> <span class="at">-q</span> <span class="at">--</span> <span class="at">-r</span></span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./weasel</span> <span class="at">-q</span> <span class="at">-q-</span> <span class="at">-r</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./weasel -q -- -r
./weasel -q -q- -r</code></pre>
<p>Then it <em>would</em> set quiet output then see the <code>--</code> (the <code>-</code> option
itself) and then the target string would <em>literally</em> be set to <code>-r</code> because
it no longer cares about the <code>-</code> for option parsing. In other words options
@@ -536,15 +536,15 @@ monkey mode be disabled? If yes how do we know if monkey mode was specially
requested? There are at least two ways to go about it: I took the monkey safe
(‘fool safe’) method; *if you explicitly request monkey mode you cannot disable
it in the same invocation of <code>weasel</code>!</p>
<div class="sourceCode" id="cb26"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./weasel <span class="at">-qr101r5r101r1r</span> test</span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">quiet</span> output</span>
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">mutation</span> rate out of range</span>
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">mutation</span> rate out of range</span>
<span id="cb26-5"><a href="#cb26-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">mutation</span> rate out of range</span>
<span id="cb26-6"><a href="#cb26-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">target</span> <span class="st">&#39;test&#39;</span></span>
<span id="cb26-7"><a href="#cb26-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">mutation</span> rate 0</span>
<span id="cb26-8"><a href="#cb26-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">monkey</span> at typewriter</span>
<span id="cb26-9"><a href="#cb26-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">Generation</span> 16844 Offspring 22: TEST</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> $ ./weasel -qr101r5r101r1r test
quiet output
mutation rate out of range
mutation rate out of range
mutation rate out of range
target &#39;test&#39;
mutation rate 0
monkey at typewriter
Generation 16844 Offspring 22: TEST</code></pre>
<p>So in this case I joined the options in the following order:</p>
<ol type="1">
<li><p><code>-q</code></p>
@@ -575,24 +575,24 @@ matter</em> because of truncation but I do in any case specifically check for <c
<p>Given that it was a short string it did find the answer relatively quickly, even
in monkey mode.</p>
<p>Another example:</p>
<div class="sourceCode" id="cb27"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./weasel <span class="at">-q</span> <span class="at">-r101</span> test <span class="at">-r5</span></span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">quiet</span> output</span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">mutation</span> rate out of range</span>
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">target</span> <span class="st">&#39;test&#39;</span></span>
<span id="cb27-5"><a href="#cb27-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">mutation</span> rate 5</span>
<span id="cb27-6"><a href="#cb27-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">Generation</span> 109 Offspring 13: TEST</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> $ ./weasel -q -r101 test -r5
quiet output
mutation rate out of range
target &#39;test&#39;
mutation rate 5
Generation 109 Offspring 13: TEST</code></pre>
<p>In this case I also enabled quiet mode but I didn’t join the options; the
<code>-r101</code> reports that it’s out of range and sets monkey mode. I then specify
the target string and then set a valid mutation rate. This disabled monkey mode
which means that it’ll use the genetic algorithm.</p>
<p>One more example of monkey mode:</p>
<div class="sourceCode" id="cb28"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./weasel <span class="at">-q</span> <span class="at">-mr101</span> test <span class="at">-r5</span></span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">quiet</span> output</span>
<span id="cb28-3"><a href="#cb28-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">mutation</span> rate out of range</span>
<span id="cb28-4"><a href="#cb28-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">target</span> <span class="st">&#39;test&#39;</span></span>
<span id="cb28-5"><a href="#cb28-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">mutation</span> rate 5</span>
<span id="cb28-6"><a href="#cb28-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">monkey</span> at typewriter</span>
<span id="cb28-7"><a href="#cb28-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">Generation</span> 465298 Offspring 10: TEST</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> $ ./weasel -q -mr101 test -r5
quiet output
mutation rate out of range
target &#39;test&#39;
mutation rate 5
monkey at typewriter
Generation 465298 Offspring 10: TEST</code></pre>
<p>Here I also requested quiet output and then <em>explicitly requested that Eric the
monkey types.</em> After this I set the mutation rate to be 101 which would have
set monkey mode (<em>in this case only temporarily as I later set it to a valid
@@ -676,10 +676,10 @@ file and pass each string to the program itself</em>. I’ve included a script
<code>test.sh</code> and a file of sample input <code>test-strings.txt</code> that you can play
with.</p>
<p>Try:</p>
<div class="sourceCode" id="cb33"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> test</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make test</code></pre>
<p>This will essentially make sure the program is compiled and then do:</p>
<div class="sourceCode" id="cb34"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">chmod</span> +x test.sh</span>
<span id="cb34-2"><a href="#cb34-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./test.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> chmod +x test.sh
./test.sh</code></pre>
<p>The script will first try compiling the program (if necessary) and if it fails
for any reason it will exit; else it will read each line in the file
<code>test-strings.txt</code> (if the file doesn’t exist or can’t be read the script will
@@ -689,7 +689,7 @@ string it’ll sleep approximately 2 seconds and then read the next string
processed).</p>
<p>You can pass additional options directly to the script but remember that it
stops when there are no more strings in the file - so if you try:</p>
<div class="sourceCode" id="cb35"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./test.sh</span> <span class="at">-q</span> test</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./test.sh -q test</code></pre>
<p>The final string <code>test</code> won’t be searched for; it will however run the program
in all invocations with quiet output enabled. The following are some notes about
how the shell and the program interact with each other:</p>
@@ -713,11 +713,11 @@ and the fact the program does not accept spaces other than a literal space<br />
program prints an error message and then exits (returning 1). But since the
keyboard doesn’t have <code>'\n'</code> if you were to type a <code>'</code> and send a
<code>'\n'</code> before the closing <code>'</code> you might see something like:</p>
<div class="sourceCode" id="cb36"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> ./weasel <span class="st">&#39;!!</span></span>
<span id="cb36-2"><a href="#cb36-2" aria-hidden="true" tabindex="-1"></a><span class="st"> &gt; &#39;</span></span>
<span id="cb36-3"><a href="#cb36-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-4"><a href="#cb36-4" aria-hidden="true" tabindex="-1"></a> <span class="st">&#39;</span></span>
<span id="cb36-5"><a href="#cb36-5" aria-hidden="true" tabindex="-1"></a><span class="st"> &#39;</span> not in keyboard <span class="st">&quot; !&quot;</span>#$<span class="op">&lt;</span>%:<span class="op">&gt;&amp;</span><span class="st">&#39;()*+,-./0123456789;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~&quot;</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> $ ./weasel &#39;!!
&gt; &#39;
&#39;
&#39; not in keyboard &quot; !&quot;#$&lt;%:&gt;&amp;&#39;()*+,-./0123456789;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~&quot;</code></pre>
<p>I showed that <code>'</code> is in the keyboard already; however the user sent a
<code>\n</code> (hence the secondary prompt <code>&gt;</code> on line two) before literally typing the
closing <code>'</code> (also line two). But in order to make it clear what character is invalid I
@@ -737,9 +737,9 @@ rather confusing and hard to read.</p>
as well as some C keywords.</p></li>
<li><p>The way <code>main()</code> is declared is:</p></li>
</ol>
<div class="sourceCode" id="cb37"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a> <span class="co">/* Special C main() handler (encapsulation): */</span></span>
<span id="cb37-2"><a href="#cb37-2" aria-hidden="true" tabindex="-1"></a> <span class="pp">#define r</span><span class="op">(</span><span class="pp">main</span><span class="op">)</span><span class="pp"> main</span></span>
<span id="cb37-3"><a href="#cb37-3" aria-hidden="true" tabindex="-1"></a> r<span class="op">(</span>k main<span class="op">(</span>k a<span class="op">,</span> E <span class="op">**</span>V<span class="op">))</span> <span class="op">{</span></span></code></pre></div>
<pre class="&lt;!---c--&gt;"><code> /* Special C main() handler (encapsulation): */
#define r(main) main
r(k main(k a, E **V)) {</code></pre>
<p>It appears to be recursively defined but is it? And is it truly
encapsulation? And is it executing code of any kind? It mightn’t seem like it
isn’t encapsulation and also isn’t executing code but assuming it’s
@@ -813,7 +813,7 @@ won’t spoil; yes this ironically and amusingly means I’ve left a rotten egg
somewhere!).</p>
<p>The Makefile simplifies how to reconfigure this value with the variable
<code>MAX_SIZE</code>:</p>
<div class="sourceCode" id="cb38"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> clobber MAX_SIZE=55 all</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make clobber MAX_SIZE=55 all</code></pre>
<p>The next macro that can be reconfigured, <code>M</code> (or <code>MAX_ATTEMPTS</code> in the
Makefile), is the maximum attempts before giving up. This was added as another
feature in 2024 but it was not made an alt version because there already is an
@@ -821,7 +821,7 @@ alt version. This macro allows for seeing what happens when reaching the maximum
number attempts without waiting for a very long time.</p>
<p>The Makefile simplifies how to reconfigure this value with the variable
<code>MAX_ATTEMPTS</code>:</p>
<div class="sourceCode" id="cb39"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> clobber MAX_ATTEMPTS=100 all</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make clobber MAX_ATTEMPTS=100 all</code></pre>
<p>The final macro, <code>N</code> (or <code>OFFSPRING</code> in the Makefile), is the number of offspring
per generation.</p>
<p>Anything less than 4 will be set to 3 (that’s not a typo!) and this is part of
@@ -831,23 +831,23 @@ both individually and together the program will use varying amounts of memory
and the larger the values the more memory it’ll require.</p>
<p>The Makefile simplifies how to reconfigure this value with the variable
<code>OFFSPRING</code>:</p>
<div class="sourceCode" id="cb40"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> clobber OFFSPRING=55 all</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make clobber OFFSPRING=55 all</code></pre>
<h3 id="compilation"><a name="compiling">Compilation</a></h3>
<p>Skip to <a href="#portability">Portability</a>.</p>
<p>The following options <strong>must always be passed to the compiler:</strong></p>
<div class="sourceCode" id="cb41"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">-DQ=</span><span class="st">&#39;typedef&#39;</span> <span class="at">-D</span><span class="st">&#39;g(o)&#39;</span><span class="op">=</span><span class="st">&#39;goto o;&#39;</span> <span class="at">-D</span><span class="st">&#39;w(x)&#39;</span><span class="op">=</span><span class="st">&quot;x:&quot;</span> <span class="at">-D</span><span class="st">&#39;H(main)&#39;</span><span class="op">=</span><span class="st">&#39;r(main)&#39;</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> -DQ=&#39;typedef&#39; -D&#39;g(o)&#39;=&#39;goto o;&#39; -D&#39;w(x)&#39;=&quot;x:&quot; -D&#39;H(main)&#39;=&#39;r(main)&#39;</code></pre>
<p>which running <code>make</code> will always do.</p>
<p>If you want to increase the number of offspring to <code>50</code> (<code>N</code>) and the size of the
chromosome to <code>75</code> (<code>S</code>) you would do:</p>
<div class="sourceCode" id="cb42"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb42-1"><a href="#cb42-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> clobber OFFSPRING=50 MAX_SIZE=75 everything</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make clobber OFFSPRING=50 MAX_SIZE=75 everything</code></pre>
<p>If you wanted to change <code>N</code> to <code>3</code>:</p>
<div class="sourceCode" id="cb43"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb43-1"><a href="#cb43-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> clobber OFFSPRING=3 everything</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make clobber OFFSPRING=3 everything</code></pre>
<p>Remember that it cannot be less than <code>3</code>; <em>more correctly if it’s less than
4 it’s redefined to 3</em> so you could have passed in <code>-DN=2</code> (or <code>MAX_SIZE=2</code>) and have the same
result. Remember too that <code>S</code> (<code>MAX_SIZE</code>) cannot be less than <code>38</code>. Both <code>S</code> and
<code>N</code> are capped at <code>SIZE_MAX - 1</code> or whatever <code>M</code> (<code>MAX_ATTEMPTS</code>) is set to.</p>
<p>If you wanted to change the maximum number attempts to 100 you could do:</p>
<div class="sourceCode" id="cb44"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb44-1"><a href="#cb44-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> clobber MAX_ATTEMPTS=100 everything</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make clobber MAX_ATTEMPTS=100 everything</code></pre>
<h3 id="portability"><a name="portability">Portability</a></h3>
<p>Skip to <a href="#bugs">An aside on bugs</a>.</p>
<p>This entry requires at least C99 even if you translate digraphs. The program
@@ -857,43 +857,43 @@ smaller and this I believe includes <code>SIZE_MAX</code>). I don’t think Wind
ports would have many issues (if any) either but I have no way to test this.
Originally I tested it on the below systems.</p>
<h4 id="fedora-26">Fedora 26:</h4>
<div class="sourceCode" id="cb45"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb45-1"><a href="#cb45-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> clang <span class="at">--version</span><span class="kw">|</span><span class="fu">head</span> <span class="at">-n1</span></span>
<span id="cb45-2"><a href="#cb45-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">clang</span> version 4.0.1 <span class="er">(</span><span class="ex">tags/RELEASE_401/final</span><span class="kw">)</span></span>
<span id="cb45-3"><a href="#cb45-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> gcc <span class="at">--version</span><span class="kw">|</span><span class="fu">head</span> <span class="at">-n1</span></span>
<span id="cb45-4"><a href="#cb45-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">gcc</span> <span class="er">(</span><span class="ex">GCC</span><span class="kw">)</span> <span class="ex">7.3.1</span> 20180130 <span class="er">(</span><span class="ex">Red</span> Hat 7.3.1-2<span class="kw">)</span></span>
<span id="cb45-5"><a href="#cb45-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> /lib64/libc-2.25.so <span class="kw">|</span><span class="fu">head</span> <span class="at">-n1</span><span class="kw">|</span><span class="fu">cut</span> <span class="at">-d</span><span class="st">&#39;,&#39;</span> <span class="at">-f1-1</span></span>
<span id="cb45-6"><a href="#cb45-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">GNU</span> C Library <span class="er">(</span><span class="ex">GNU</span> libc<span class="kw">)</span> <span class="ex">stable</span> release version 2.25</span>
<span id="cb45-7"><a href="#cb45-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> lscpu <span class="kw">|</span><span class="fu">grep</span> Endian</span>
<span id="cb45-8"><a href="#cb45-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">Byte</span> Order: Little Endian</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> $ clang --version|head -n1
clang version 4.0.1 (tags/RELEASE_401/final)
$ gcc --version|head -n1
gcc (GCC) 7.3.1 20180130 (Red Hat 7.3.1-2)
$ /lib64/libc-2.25.so |head -n1|cut -d&#39;,&#39; -f1-1
GNU C Library (GNU libc) stable release version 2.25
$ lscpu |grep Endian
Byte Order: Little Endian</code></pre>
<h4 id="centos-linux-release-7.4.1708-core">CentOS Linux release 7.4.1708 (Core)</h4>
<div class="sourceCode" id="cb46"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb46-1"><a href="#cb46-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> clang <span class="at">--version</span><span class="kw">|</span><span class="fu">head</span> <span class="at">-n1</span></span>
<span id="cb46-2"><a href="#cb46-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">clang</span> version 3.4.2 <span class="er">(</span><span class="ex">tags/RELEASE_34/dot2-final</span><span class="kw">)</span></span>
<span id="cb46-3"><a href="#cb46-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> gcc <span class="at">--version</span><span class="kw">|</span><span class="fu">head</span> <span class="at">-n1</span></span>
<span id="cb46-4"><a href="#cb46-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">gcc</span> <span class="er">(</span><span class="ex">GCC</span><span class="kw">)</span> <span class="ex">4.8.5</span> 20150623 <span class="er">(</span><span class="ex">Red</span> Hat 4.8.5-16<span class="kw">)</span></span>
<span id="cb46-5"><a href="#cb46-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> /lib64/libc-2.17.so <span class="kw">|</span><span class="fu">head</span> <span class="at">-n1</span> <span class="kw">|</span><span class="fu">cut</span> <span class="at">-d,</span> <span class="at">-f1-1</span></span>
<span id="cb46-6"><a href="#cb46-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">GNU</span> C Library <span class="er">(</span><span class="ex">GNU</span> libc<span class="kw">)</span> <span class="ex">stable</span> release version 2.17</span>
<span id="cb46-7"><a href="#cb46-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> lscpu <span class="kw">|</span><span class="fu">grep</span> Endian</span>
<span id="cb46-8"><a href="#cb46-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">Byte</span> Order: Little Endian</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> $ clang --version|head -n1
clang version 3.4.2 (tags/RELEASE_34/dot2-final)
$ gcc --version|head -n1
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)
$ /lib64/libc-2.17.so |head -n1 |cut -d, -f1-1
GNU C Library (GNU libc) stable release version 2.17
$ lscpu |grep Endian
Byte Order: Little Endian</code></pre>
<h4 id="fedora-27">Fedora 27:</h4>
<div class="sourceCode" id="cb47"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb47-1"><a href="#cb47-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> clang <span class="at">--version</span><span class="kw">|</span><span class="fu">head</span> <span class="at">-n1</span></span>
<span id="cb47-2"><a href="#cb47-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">clang</span> version 5.0.1 <span class="er">(</span><span class="ex">tags/RELEASE_501/final</span><span class="kw">)</span></span>
<span id="cb47-3"><a href="#cb47-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> gcc <span class="at">--version</span><span class="kw">|</span><span class="fu">head</span> <span class="at">-n1</span></span>
<span id="cb47-4"><a href="#cb47-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">gcc</span> <span class="er">(</span><span class="ex">GCC</span><span class="kw">)</span> <span class="ex">7.3.1</span> 20180303 <span class="er">(</span><span class="ex">Red</span> Hat 7.3.1-5<span class="kw">)</span></span>
<span id="cb47-5"><a href="#cb47-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> /lib64/libc-2.26.so <span class="kw">|</span><span class="fu">head</span> <span class="at">-n1</span><span class="kw">|</span><span class="fu">cut</span> <span class="at">-d,</span> <span class="at">-f1-1</span></span>
<span id="cb47-6"><a href="#cb47-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">GNU</span> C Library <span class="er">(</span><span class="ex">GNU</span> libc<span class="kw">)</span> <span class="ex">stable</span> release version 2.26</span>
<span id="cb47-7"><a href="#cb47-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> lscpu <span class="kw">|</span><span class="fu">grep</span> Endian</span>
<span id="cb47-8"><a href="#cb47-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">Byte</span> Order: Little Endian</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> $ clang --version|head -n1
clang version 5.0.1 (tags/RELEASE_501/final)
$ gcc --version|head -n1
gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
$ /lib64/libc-2.26.so |head -n1|cut -d, -f1-1
GNU C Library (GNU libc) stable release version 2.26
$ lscpu |grep Endian
Byte Order: Little Endian</code></pre>
<h4 id="macos">macOS:</h4>
<p>System Version: macOS 10.13.4 (17E199)
Kernel Version: Darwin 17.5.0</p>
<div class="sourceCode" id="cb48"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb48-1"><a href="#cb48-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> gcc <span class="at">-v</span></span>
<span id="cb48-2"><a href="#cb48-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">Configured</span> with: <span class="at">--prefix</span><span class="op">=</span>/Library/Developer/CommandLineTools/usr <span class="at">--with-gxx-include-dir</span><span class="op">=</span>/usr/include/c++/4.2.1</span>
<span id="cb48-3"><a href="#cb48-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">Apple</span> LLVM version 9.1.0 <span class="er">(</span><span class="ex">clang-902.0.39.1</span><span class="kw">)</span></span>
<span id="cb48-4"><a href="#cb48-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">Target:</span> x86_64-apple-darwin17.5.0</span>
<span id="cb48-5"><a href="#cb48-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">Thread</span> model: posix</span>
<span id="cb48-6"><a href="#cb48-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">InstalledDir:</span> /Library/Developer/CommandLineTools/usr/bin</span>
<span id="cb48-7"><a href="#cb48-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> uname <span class="at">-srmv</span></span>
<span id="cb48-8"><a href="#cb48-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">Darwin</span> 17.5.0 Darwin Kernel Version 17.5.0: Mon Mar 5 22:24:32 PST 2018<span class="kw">;</span> <span class="ex">root:xnu-4570.51.1~1/RELEASE_X86_64</span> x86_64</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> $ gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ uname -srmv
Darwin 17.5.0 Darwin Kernel Version 17.5.0: Mon Mar 5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64</code></pre>
<h4 id="an-aside"><a name="bugs">An aside</a></h4>
<p>Skip to <a href="#rpm">Installing</a>.</p>
<p>Any undocumented bugs are the result of insolent monkeys tampering with any
@@ -1012,8 +1012,8 @@ When we found others were actually trying to programs with A, we quickly added
additional cryptic features and evolved into B, BCPL, and finally C. We stopped
when we got a clean compile on the following syntax:</p>
</blockquote>
<div class="sourceCode" id="cb49"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb49-1"><a href="#cb49-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span><span class="op">(;</span>P<span class="op">(</span><span class="st">&quot;</span><span class="sc">\n</span><span class="st">&quot;</span><span class="op">),</span>R<span class="op">=;</span>P<span class="op">(</span><span class="st">&quot;|&quot;</span><span class="op">))</span><span class="cf">for</span><span class="op">(</span>e<span class="op">=</span>C<span class="op">;</span>e<span class="op">=</span>P<span class="op">(</span><span class="st">&quot;_&quot;</span><span class="op">+(*</span>u<span class="op">++/</span></span>
<span id="cb49-2"><a href="#cb49-2" aria-hidden="true" tabindex="-1"></a> <span class="dv">8</span><span class="op">)%</span><span class="dv">2</span><span class="op">))</span>P<span class="op">(</span><span class="st">&quot;|&quot;</span><span class="op">+(*</span>u<span class="op">/</span><span class="dv">4</span><span class="op">)%</span><span class="dv">2</span><span class="op">);</span></span></code></pre></div>
<pre class="&lt;!---c--&gt;"><code> for(;P(&quot;\n&quot;),R=;P(&quot;|&quot;))for(e=C;e=P(&quot;_&quot;+(*u++/
8)%2))P(&quot;|&quot;+(*u/4)%2);</code></pre>
<blockquote>
<p>“To think that modern programmers would try to use a language that allowed
such a statement was beyond our comprehension! We actually thought of selling
@@ -1054,8 +1054,8 @@ person to talk about it with is more than welcome!</em>). Ken suggested that the
is a lack of common sense but since he was part of its creation I don’t think
it’s a bad thing; <strong>on the contrary it makes all of us C programmers even more
talented! :)</strong> I do wonder if he tested that bit of C code though:</p>
<div class="sourceCode" id="cb50"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb50-1"><a href="#cb50-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span><span class="op">(;</span>P<span class="op">(</span><span class="st">&quot;</span><span class="sc">\n</span><span class="st">&quot;</span><span class="op">),</span>R<span class="op">=;</span>P<span class="op">(</span><span class="st">&quot;|&quot;</span><span class="op">))</span><span class="cf">for</span><span class="op">(</span>e<span class="op">=</span>C<span class="op">;</span>e<span class="op">=</span>P<span class="op">(</span><span class="st">&quot;_&quot;</span><span class="op">+(*</span>u<span class="op">++/</span></span>
<span id="cb50-2"><a href="#cb50-2" aria-hidden="true" tabindex="-1"></a> <span class="dv">8</span><span class="op">)%</span><span class="dv">2</span><span class="op">))</span>P<span class="op">(</span><span class="st">&quot;|&quot;</span><span class="op">+(*</span>u<span class="op">/</span><span class="dv">4</span><span class="op">)%</span><span class="dv">2</span><span class="op">);</span></span></code></pre></div>
<pre class="&lt;!---c--&gt;"><code> for(;P(&quot;\n&quot;),R=;P(&quot;|&quot;))for(e=C;e=P(&quot;_&quot;+(*u++/
8)%2))P(&quot;|&quot;+(*u/4)%2);</code></pre>
<p>How is <code>R=;</code> valid? Since I don’t have the context maybe there is something
I’m missing but either way it’s a funny piece. It could also be for irony itself
(actually I had previously thought of somehow implementing something like that
+3 -3
View File
@@ -4,21 +4,21 @@ This entry requires SDL2 to be installed. See [FAQ 3.8: How do I compile an
IOCCC entry that requires SDL1 or SDL2?](../../faq.html#SDL) if you don't have it
installed and don't know how to do so.
```sh
```<!---sh-->
make
```
## To use:
```sh
```<!---sh-->
./prog
```
## Try:
```sh
```<!---sh-->
./prog ioccc.txt
./prog prog.c
+9 -9
View File
@@ -144,17 +144,17 @@ Location: <a href="../../location.html#AU">AU</a> - <em>Commonwealth of Australi
<p>This entry requires SDL2 to be installed. See <a href="../../faq.html#SDL">FAQ 3.8: How do I compile an
IOCCC entry that requires SDL1 or SDL2?</a> if you don’t have it
installed and don’t know how to do so.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog</code></pre>
<h2 id="try">Try:</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> ioccc.txt</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> prog.c</span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> sand.txt</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> sand.alt.txt</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog ioccc.txt
./prog prog.c
./prog sand.txt
./prog sand.alt.txt</code></pre>
<p>NOTE: these invocations will take quite some time to finish.</p>
<h2 id="judges-remarks">Judges’ remarks:</h2>
<p>Can you explain the behavior of the program when <a href="ioccc.txt">ioccc.txt</a> is given
+3 -3
View File
@@ -1,6 +1,6 @@
## To build:
```sh
```<!---sh-->
make
```
@@ -18,7 +18,7 @@ For more detailed information see [2018 hou bugs](../../bugs.html#2018_hou).
## To use:
```sh
```<!---sh-->
./prog < input.json > output.html
```
@@ -27,7 +27,7 @@ View `output.html` in a browser.
## Try:
```sh
```<!---sh-->
./try.sh
```
+3 -3
View File
@@ -141,16 +141,16 @@ Location: <a href="../../location.html#CN">CN</a> - <em>People’s Republic of C
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<h3 id="bugs-and-misfeatures">Bugs and (Mis)features:</h3>
<p>The current status of this entry is:</p>
<pre><code> STATUS: INABIAF - please **DO NOT** fix</code></pre>
<p>For more detailed information see <a href="../../bugs.html#2018_hou">2018 hou bugs</a>.</p>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op">&lt;</span> input.json <span class="op">&gt;</span> output.html</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog &lt; input.json &gt; output.html</code></pre>
<p>View <code>output.html</code> in a browser.</p>
<h2 id="try">Try:</h2>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.sh</code></pre>
<p>The script will generate a JSON file called <code>ioccc.json</code>, showing it via
<code>tee(1)</code> and then run the program on that. Can you find any problem with the
JSON file? What happens if you try and fix it?</p>
+11 -11
View File
@@ -1,6 +1,6 @@
## To build:
```sh
```<!---sh-->
make
```
@@ -8,7 +8,7 @@ If you wish to save state so that you can run the program and keep files changed
(for instance you don't want to compile `mullender.c` again) you can compile it
like:
```sh
```<!---sh-->
make clobber SAVE=1 all
```
@@ -31,14 +31,14 @@ For more detailed information see [2018 mills bugs](../../bugs.html#2018_mills).
## To use:
```sh
```<!---sh-->
./prog
```
## Try:
```sh
```<!---sh-->
./prog
```
@@ -47,7 +47,7 @@ At the `>boot` prompt, type return.
At the `:` prompt, type `rk(0,0)rkunix` and wait for it to initialise itself.
Now try typing:
```sh
```<!---sh-->
cat > prog.c
main(){ printf("Hello, world!\n"); }
^D
@@ -59,7 +59,7 @@ where `^D` is EOF.
Next try:
```sh
```<!---sh-->
cc mullender.c
a.out
```
@@ -81,7 +81,7 @@ Do small machines only need small programs? This program weighs in at just
This program can take you back to the start of everything, it is possible to
run v0. Just type:
```sh
```<!---sh-->
./v0
```
@@ -91,7 +91,7 @@ You will be greeted with a familiar prompt of "login". The username and
password are "dmr" and "dmr". To make things more familiar you'll need to
create '.' as it hasn't been invented yet on this image!
```sh
```<!---sh-->
@ ln dd dmr .
```
@@ -102,7 +102,7 @@ together like `ops.s bl.s hello.s bi.s` (in that order) to produce a.out!
But wait, we said this was the start of it all! This program can also run a
program that replaces an even larger machine that can run BSD 2.9. To start this,
```sh
```<!---sh-->
./prog
```
@@ -118,7 +118,7 @@ shown earlier.
But wait, there is even more! Try:
```sh
```<!---sh-->
./v6
```
@@ -220,7 +220,7 @@ only a quarter of a century ago -- how much could things have changed?).
Let's try some:
```sh
```<!---sh-->
# ls
.cshrc .profile boot hkunix mnt tmp
.login 2.9stamp dev lib mullender.c unix
+24 -24
View File
@@ -141,11 +141,11 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<p>If you wish to save state so that you can run the program and keep files changed
(for instance you don’t want to compile <code>mullender.c</code> again) you can compile it
like:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> clobber SAVE=1 all</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make clobber SAVE=1 all</code></pre>
<p>Make sure that if you do add a file (including by compiling code) that before
you exit (ctrl-e) you type in <code>sync</code>! Otherwise the file might not exist or it
will be corrupt if it does.</p>
@@ -155,21 +155,21 @@ will be corrupt if it does.</p>
STATUS: INABIAF - please **DO NOT** fix</code></pre>
<p>For more detailed information see <a href="../../bugs.html#2018_mills">2018 mills bugs</a>.</p>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog</code></pre>
<h2 id="try">Try:</h2>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog</code></pre>
<p>At the <code>&gt;boot</code> prompt, type return.</p>
<p>At the <code>:</code> prompt, type <code>rk(0,0)rkunix</code> and wait for it to initialise itself.
Now try typing:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> <span class="op">&gt;</span> prog.c</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">main()</span><span class="kw">{</span> <span class="bu">printf</span><span class="er">(</span><span class="st">&quot;Hello, world!\n&quot;</span><span class="kw">);</span> <span class="kw">}</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">^D</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> prog.c</span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">a.out</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> cat &gt; prog.c
main(){ printf(&quot;Hello, world!\n&quot;); }
^D
cc prog.c
a.out</code></pre>
<p>where <code>^D</code> is EOF.</p>
<p>Next try:</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> mullender.c</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">a.out</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> cc mullender.c
a.out</code></pre>
<p>… and enjoy the classic <a href="../../1984/mullender/index.html">1984/mullender</a> entry as
it would have been in 1984 with a VAX-11/PDP-11! Once it reaches the end of the
line, hit enter and see what happens again. When you’re tired of it hit ctrl-c.</p>
@@ -180,18 +180,18 @@ line, hit enter and see what happens again. When you’re tired of it hit ctrl-c
3636 bytes, which is considerably lighter than the original machine it can replace.</p>
<p>This program can take you back to the start of everything, it is possible to
run v0. Just type:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./v0</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./v0</code></pre>
<p>NOTE: To quit v0, press Control-E.</p>
<p>You will be greeted with a familiar prompt of “login”. The username and
password are “dmr” and “dmr”. To make things more familiar you’ll need to
create ‘.’ as it hasn’t been invented yet on this image!</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">@</span> ln dd dmr .</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> @ ln dd dmr .</code></pre>
<p>An <code>ls</code> will reveal that C hasn’t been invented yet! IOBCC anyone? The
compiler is <code>bc</code>. It produces assembly, which will then need to be assembled
together like <code>ops.s bl.s hello.s bi.s</code> (in that order) to produce a.out!</p>
<p>But wait, we said this was the start of it all! This program can also run a
program that replaces an even larger machine that can run BSD 2.9. To start this,</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog</code></pre>
<p>At the <code>&gt;boot</code> prompt, type return.</p>
<p>At the “:” prompt, type <code>rk(0,0)rkunix</code>.</p>
<p>NOTE: To quit prog, press Control-E.</p>
@@ -199,7 +199,7 @@ program that replaces an even larger machine that can run BSD 2.9. To start this
the very first IOCCC entries <a href="../../1984/mullender/index.html">1984/mullender</a>, as
shown earlier.</p>
<p>But wait, there is even more! Try:</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./v6</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./v6</code></pre>
<p>At the <code>@</code> prompt, type <code>rkunix</code>. You might want to type <code>stty -lcase</code> as
otherwise the output will be in all caps.</p>
<p>NOTE: To quit v6, press Control-E.</p>
@@ -269,15 +269,15 @@ If so, consider a <code>make clean</code> to start from scratch.</p>
root prompt. Most of the commands you are familiar with work here (this was
only a quarter of a century ago – how much could things have changed?).
Let’s try some:</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># ls</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">.cshrc</span> .profile boot hkunix mnt tmp</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">.login</span> 2.9stamp dev lib mullender.c unix</span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">.msgsrc</span> bin etc lost+found rkunix usr</span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a> <span class="co"># df</span></span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">Filesystem</span> Mounted on kbytes used free % used</span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">/dev/rk0</span> / 1958 1688 270 86%</span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true" tabindex="-1"></a> <span class="co"># bin/cc mullender.c</span></span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true" tabindex="-1"></a> <span class="co"># ./a.out</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> # ls
.cshrc .profile boot hkunix mnt tmp
.login 2.9stamp dev lib mullender.c unix
.msgsrc bin etc lost+found rkunix usr
# df
Filesystem Mounted on kbytes used free % used
/dev/rk0 / 1958 1688 270 86%
# bin/cc mullender.c
# ./a.out</code></pre>
<p>The program you’ve just run was the [winning entry of the first IOCCC contest from
1984] <a href="../../1984/mullender/mullender.c" title="mullender.c">1</a> (or was it 1894?), a personal favorite of mine. It is rather
tightly bound to running on either a PDP-11 or a VAX-11. Now you have one.</p>
+5 -5
View File
@@ -1,13 +1,13 @@
## To build:
```sh
```<!---sh-->
make
```
## To use:
```sh
```<!---sh-->
./prog
```
@@ -17,7 +17,7 @@
On a terminal that supports 24 bit color, has black background, and size at
least 125x38, try:
```sh
```<!---sh-->
./try.sh
```
@@ -40,13 +40,13 @@ And those in the deep south might wish to go north for a better view.
### How to build:
```sh
```<!---sh-->
cc -o prog -std=gnu11 -O3 prog.c
```
or
```sh
```<!---sh-->
make
```
+5 -5
View File
@@ -141,13 +141,13 @@ Location: <a href="../../location.html#FI">FI</a> - <em>Republic of Finland </em
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog</code></pre>
<h2 id="try">Try:</h2>
<p>On a terminal that supports 24 bit color, has black background, and size at
least 125x38, try:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.sh</code></pre>
<h2 id="judges-remarks">Judges’ remarks:</h2>
<p>It is said by some students of Astronomy:</p>
<pre><code> Oh, Be A Fine Gal, Kiss Me!
@@ -157,9 +157,9 @@ You might wish, on a star, to better understand the colors being displayed.
And those in the deep south might wish to go north for a better view.</p>
<h2 id="authors-remarks">Author’s remarks:</h2>
<h3 id="how-to-build">How to build:</h3>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> <span class="at">-o</span> prog <span class="at">-std</span><span class="op">=</span>gnu11 <span class="at">-O3</span> prog.c</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> cc -o prog -std=gnu11 -O3 prog.c</code></pre>
<p>or</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<h3 id="poster">Poster:</h3>
<p>You can generate an A3 sized poster by <em>make docs</em>. This command creates a pdf
file <em>poikola.pdf</em>.</p>
+3 -3
View File
@@ -1,6 +1,6 @@
## To build:
```sh
```<!---sh-->
make
```
@@ -18,14 +18,14 @@ For more detailed information see [2018 vokes bugs](../../bugs.html#2018_vokes).
## To use:
```sh
```<!---sh-->
./prog < file.txt
```
## Try:
```sh
```<!---sh-->
./try.sh
```
+3 -3
View File
@@ -141,15 +141,15 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<h3 id="bugs-and-misfeatures">Bugs and (Mis)features:</h3>
<p>The current status of this entry is:</p>
<pre><code> STATUS: INABIAF - please **DO NOT** fix</code></pre>
<p>For more detailed information see <a href="../../bugs.html#2018_vokes">2018 vokes bugs</a>.</p>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="op">&lt;</span> file.txt</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./prog &lt; file.txt</code></pre>
<h2 id="try">Try:</h2>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.sh</code></pre>
<h2 id="judges-remarks">Judges’ remarks:</h2>
<p>What this program does is not witchcraft and there are no spectres, but you
might have a meltdown trying to work it all out (look at the source code to
+9 -9
View File
@@ -1,6 +1,6 @@
## To build:
```sh
```<!---sh-->
make
```
@@ -10,7 +10,7 @@
The author suggested that after compilation one should look at the generated
files. For instance:
```sh
```<!---sh-->
less generated1.c
less generated2.c
less generated3.c
@@ -19,7 +19,7 @@ files. For instance:
## Try:
```sh
```<!---sh-->
./try.sh
```
@@ -44,7 +44,7 @@ of `./left`, `./right` and `./shift` and the additionally generated programs.
The final message can be revealed using
```sh
```<!---sh-->
./msg9 < prog.c
```
@@ -59,7 +59,7 @@ But what combinations will generate `./msg3`, `./msg4`, `./msg5`, `./msg6`,
`Nuko` is a text rotator: given some text in `stdin`, `Nuko` will write the
same text to `stdout`, but rotated 90 degrees counterclockwise.
```sh
```<!---sh-->
cc prog.c -o left
./left < input.txt > rotated_counterclockwise.txt
```
@@ -68,7 +68,7 @@ Due to static memory allocation, only the first 1K columns by 1K rows
are rotated, the rest are silently ignored. But fear not, a separate
tool with dynamic memory allocation is included:
```sh
```<!---sh-->
./left < prog.c > r1.c
cc r1.c -o right
./right < input.txt > rotated_clockwise.txt
@@ -83,7 +83,7 @@ rotate counterclockwise once more, we get another program. This
program outputs a single message to `stdout`, which is the name of the
series that `Nuko` came from.
```sh
```<!---sh-->
./left < prog.c | ./left > r2.c
cc r2.c -o msg0
./msg0
@@ -92,7 +92,7 @@ series that `Nuko` came from.
There is one final rotation, which produces a tool that removes
leading whitespaces:
```sh
```<!---sh-->
./left < prog.c | ./left | ./left > r3.c
cc r3.c -o shift
./shift < input.txt > no_leading_space.txt
@@ -112,7 +112,7 @@ side). This shifted code behaves slightly different from the original
program. For example, here are two more messages that can be
produced:
```sh
```<!---sh-->
./shift < prog.c | ./right > msg1.c && gcc msg1.c -o msg1 && ./msg1
./shift < prog.c | ./left > msg2.c && gcc msg2.c -o msg2 && ./msg2
```
+19 -19
View File
@@ -141,15 +141,15 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> make</code></pre>
<h2 id="to-use">To use:</h2>
<p>The author suggested that after compilation one should look at the generated
files. For instance:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">less</span> generated1.c</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">less</span> generated2.c</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">less</span> generated3.c</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> less generated1.c
less generated2.c
less generated3.c</code></pre>
<h2 id="try">Try:</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./try.sh</code></pre>
<h2 id="judges-remarks">Judges’ remarks:</h2>
<p>Code should be readable in any direction! This tool will help you rotate your
code so you don’t have to stare at it sideways or even upside down. Rotating
@@ -164,21 +164,21 @@ reveal messages and one more tool that can be used to reveal the final message
hidden in the original source. All of these can be created using combinations
of <code>./left</code>, <code>./right</code> and <code>./shift</code> and the additionally generated programs.</p>
<p>The final message can be revealed using</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./msg9</span> <span class="op">&lt;</span> prog.c</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./msg9 &lt; prog.c</code></pre>
<p>But what combinations will generate <code>./msg3</code>, <code>./msg4</code>, <code>./msg5</code>, <code>./msg6</code>,
<code>./msg7</code>, <code>./msg8</code> and finally <code>./msg9</code>?</p>
<h2 id="authors-remarks">Author’s remarks:</h2>
<h3 id="tools-usage">Tools’ usage:</h3>
<p><code>Nuko</code> is a text rotator: given some text in <code>stdin</code>, <code>Nuko</code> will write the
same text to <code>stdout</code>, but rotated 90 degrees counterclockwise.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> prog.c <span class="at">-o</span> left</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./left</span> <span class="op">&lt;</span> input.txt <span class="op">&gt;</span> rotated_counterclockwise.txt</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> cc prog.c -o left
./left &lt; input.txt &gt; rotated_counterclockwise.txt</code></pre>
<p>Due to static memory allocation, only the first 1K columns by 1K rows
are rotated, the rest are silently ignored. But fear not, a separate
tool with dynamic memory allocation is included:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./left</span> <span class="op">&lt;</span> prog.c <span class="op">&gt;</span> r1.c</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> r1.c <span class="at">-o</span> right</span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./right</span> <span class="op">&lt;</span> input.txt <span class="op">&gt;</span> rotated_clockwise.txt</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./left &lt; prog.c &gt; r1.c
cc r1.c -o right
./right &lt; input.txt &gt; rotated_clockwise.txt</code></pre>
<p>For variety, this second tool rotates clockwise instead of
counterclockwise. Also, it can handle files larger than 1024x1024,
depending on how much memory you have.</p>
@@ -186,14 +186,14 @@ depending on how much memory you have.</p>
rotate counterclockwise once more, we get another program. This
program outputs a single message to <code>stdout</code>, which is the name of the
series that <code>Nuko</code> came from.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./left</span> <span class="op">&lt;</span> prog.c <span class="kw">|</span> <span class="ex">./left</span> <span class="op">&gt;</span> r2.c</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> r2.c <span class="at">-o</span> msg0</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./msg0</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./left &lt; prog.c | ./left &gt; r2.c
cc r2.c -o msg0
./msg0</code></pre>
<p>There is one final rotation, which produces a tool that removes
leading whitespaces:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./left</span> <span class="op">&lt;</span> prog.c <span class="kw">|</span> <span class="ex">./left</span> <span class="kw">|</span> <span class="ex">./left</span> <span class="op">&gt;</span> r3.c</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> r3.c <span class="at">-o</span> shift</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./shift</span> <span class="op">&lt;</span> input.txt <span class="op">&gt;</span> no_leading_space.txt</span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./left &lt; prog.c | ./left | ./left &gt; r3.c
cc r3.c -o shift
./shift &lt; input.txt &gt; no_leading_space.txt</code></pre>
<p>Where this might be useful, besides ruining the formatting of certain
files, is that it completes the set of tools needed to solve the
puzzle that is embedded in <a href="prog.c">prog.c</a>.</p>
@@ -204,8 +204,8 @@ toward one of those notches (and create a new notch on the other
side). This shifted code behaves slightly different from the original
program. For example, here are two more messages that can be
produced:</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./shift</span> <span class="op">&lt;</span> prog.c <span class="kw">|</span> <span class="ex">./right</span> <span class="op">&gt;</span> msg1.c <span class="kw">&amp;&amp;</span> <span class="fu">gcc</span> msg1.c <span class="at">-o</span> msg1 <span class="kw">&amp;&amp;</span> <span class="ex">./msg1</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./shift</span> <span class="op">&lt;</span> prog.c <span class="kw">|</span> <span class="ex">./left</span> <span class="op">&gt;</span> msg2.c <span class="kw">&amp;&amp;</span> <span class="fu">gcc</span> msg2.c <span class="at">-o</span> msg2 <span class="kw">&amp;&amp;</span> <span class="ex">./msg2</span></span></code></pre></div>
<pre class="&lt;!---sh--&gt;"><code> ./shift &lt; prog.c | ./right &gt; msg1.c &amp;&amp; gcc msg1.c -o msg1 &amp;&amp; ./msg1
./shift &lt; prog.c | ./left &gt; msg2.c &amp;&amp; gcc msg2.c -o msg2 &amp;&amp; ./msg2</code></pre>
<p>In total, there are 9 embedded strings that can be produced via a
sequence of rotates and shifts, one of which can be used to extract
the 10th final string from <a href="prog.c">prog.c</a>. The intent is to simulate those