This is a HUGE commit and this task is not done. There are still some
changes that might need to be discussed and since so much is done here I
think it's better to let this go through and then make sure everything
is okay. When the remaining references are discussed they can also be
changed.
I did NOT include changes in the tmp/OLD_manifest directory.
Some of the changes in this commit (it might be exhaustive but it might
not be - not sure):
- In the Makefiles the WINNERS was renamed AUTHORS.
- References to winners.html were changed to authors.html.
- The FAQ named anchor 'fix_a_winner' was renamed 'fix_an_entry'.
- The JSON fields (or whatever they're called) 'winner_id' and
'winner_JSON_format_version' were changed so that 'winner' is 'entry'.
- In scripts for entries 'IOCCC winner' was changed to 'IOCCC entry'.
- 'winners_text' is now 'entries_text'. It might be better to be
'entry_text' as it's per entry but this was not noticed at first. Since
this is easy to fix I am holding off on this for the meantime.
- The script tmp/update-manifest.sh now has the commit log messages
changed to the correct terms as well.
The index.html files were updated as well with any of the above
changes.
There are some references that should NOT be updated. Two examples
caught (and maybe more have slipped through that will have to be changed
back): in 1984/anonymous/README.md the author wrote back to Landon after
being told about the famous tattoo and they used the words:
.. my entry will be the first IOCCC winner ..
but since this comes from the author it should remain so.
The other one is that winners.html should still refer to winners.html as
it informs people that it's been moved to authors.html (it does redirect
too but even so if it was changed it would defeat the purpose of the
message).
With paths like authors.html I tried to copy paste so that hopefully
there are no typos. It is possible that I did not end up doing this with
all but these can be fixed when discovered.
431 lines
38 KiB
HTML
431 lines
38 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||
<!-- START: two lines up starts content from: inc/top.default.html -->
|
||
<!-- -->
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
<!-- -->
|
||
<!-- END: this line ends content from: inc/top.default.html -->
|
||
<!-- -->
|
||
<!-- The original markdown content was formed by the tool: bin/readme2index.sh -->
|
||
<!-- The HTML was converted from markdown by the tool: bin/md2html.sh -->
|
||
<!-- -->
|
||
<!-- START: this line starts content from: inc/head.default.html -->
|
||
|
||
<head>
|
||
<link rel="stylesheet" href="../../ioccc.css">
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
||
<title>2018/burton1 - Best one-liner</title>
|
||
<meta name="description" content="2018 IOCCC entry burton1 - Best one-liner">
|
||
<meta name="keywords" content="IOCCC, 2018, IOCCC 2018, IOCCC entry, burton1, Best one-liner">
|
||
</head>
|
||
|
||
<!-- END: this line ends content from: inc/head.default.html -->
|
||
<!-- START: this line starts content from: inc/body.default.html -->
|
||
|
||
<body>
|
||
|
||
<!-- END: this line ends content from: inc/body.default.html -->
|
||
<!-- START: this line starts content from: inc/header.default.html -->
|
||
|
||
<div class="header">
|
||
<img src="../../png/ioccc.png" alt="IOCCC image by Matt Zucker" width=300 height=110>
|
||
<h1>The International Obfuscated C Code Contest</h1>
|
||
<h2>2018/burton1 - Best one-liner</h2>
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/header.default.html -->
|
||
<!-- START: this line starts content from: inc/topnav.mid.html -->
|
||
|
||
<div class="topnav">
|
||
<a class="Left" href="../bellard/index.html">← bellard</a>
|
||
<a class="Left" href="../index.html">↑ 2018 ↑</a>
|
||
<a class="Left" href="../burton2/index.html">burton2 →</a>
|
||
<a class="Right" href="#inventory">Inventory</a>
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/topnav.mid.html -->
|
||
<!-- START: this line starts content from: inc/begin-row.default.html -->
|
||
|
||
<div class="row">
|
||
|
||
<!-- END: this line ends content from: inc/begin-row.default.html -->
|
||
<!-- START: this line starts content from: inc/begin-leftcolumn.default.html -->
|
||
|
||
<div class="leftcolumn">
|
||
|
||
<!-- END: this line ends content from: inc/begin-leftcolumn.default.html -->
|
||
<!-- START: this line starts content from: inc/sidenav.default.html -->
|
||
|
||
<div class="sidenav">
|
||
<a href="#content">Jump to contents</a>
|
||
</div>
|
||
<hr>
|
||
<div class="sidenav">
|
||
<a href="../../index.html">IOCCC Home</a>
|
||
<a href="../../years.html">Winning Entries</a>
|
||
<a href="../../authors.html">People who have won</a>
|
||
</div>
|
||
<hr>
|
||
<div class="sidenav">
|
||
<a href="../../news.html">IOCCC News</a>
|
||
<a href="../../faq.html#submit">How to enter the IOCCC</a>
|
||
<a href="../../faq.html">FAQ</a>
|
||
</div>
|
||
<hr>
|
||
<div class="sidenav">
|
||
<a href="../../bugs.html">Bugs & (mis)features</a>
|
||
<a href="../../faq.html#fix_an_entry">Fixing IOCCC entries</a>
|
||
<a href="../../faq.html#fix_web_site">Fixing the web site</a>
|
||
<a href="../../faq.html#fix_author">Fixing winner info</a>
|
||
<a href="../../thanks-for-help.html">Thanks for the help</a>
|
||
</div>
|
||
<hr>
|
||
<div class="sidenav">
|
||
<a href="../../judges.html">The IOCCC Judges</a>
|
||
<a href="../../contact.html">Contacting the IOCCC</a>
|
||
</div>
|
||
<hr>
|
||
<div class="sidenav">
|
||
<a href="#top">Jump to top</a>
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/sidenav.default.html -->
|
||
<!-- START: this line starts content from: inc/end-leftcolumn.default.html -->
|
||
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/end-leftcolumn.default.html -->
|
||
<!-- START: this line starts content from: inc/begin-rightcolumn.default.html -->
|
||
|
||
<div class="rightcolumn">
|
||
|
||
<!-- END: this line ends content from: inc/begin-rightcolumn.default.html -->
|
||
<!-- START: this line starts content from: inc/before-content.default.html -->
|
||
|
||
<a name="content"></a>
|
||
|
||
<!-- END: this line ends content from: inc/before-content.default.html -->
|
||
<!-- START: this line starts content for HTML phase 20 by: bin/output-index-author.sh via bin/md2html.sh -->
|
||
|
||
<!-- START: this line starts content generated by: bin/output-index-author.sh -->
|
||
|
||
<h2 id="author"><a name="author"></a>Author:</h2>
|
||
<ul>
|
||
<li>Name: <a href="../../authors.html#Dave_Burton">Dave Burton</a><br>
|
||
Location: <a href="../../location.html#US">US</a> <br><br></li>
|
||
</ul>
|
||
|
||
<!-- END: next line ends content generated by: bin/output-index-author.sh -->
|
||
|
||
<!-- END: this line ends content for HTML phase 20 by: bin/output-index-author.sh via bin/md2html.sh -->
|
||
<!-- 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>
|
||
<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"><</span> any-file</span></code></pre></div>
|
||
<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>
|
||
<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>
|
||
<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>
|
||
<p>One line, one array, one loop and one statement but it prints many
|
||
bytes. It won.</p>
|
||
<h2 id="authors-remarks">Author’s remarks:</h2>
|
||
<p>Feed this anything on <code>stdin</code>.</p>
|
||
<p>The <a href="scripthd.sh">included script.sh</a> may be used as a
|
||
driver program for this entry. It adds several nice-to-have features,
|
||
and allows salt-to-taste customizability.</p>
|
||
<p>This code has been compiled and tested on:</p>
|
||
<ul>
|
||
<li>OSX-10.11, gcc 4.2.1 and clang 3.0, -O0 and -O3</li>
|
||
<li>X86-Linux, gcc 4.1.2 and 4.8.4, -O0 and -O3</li>
|
||
<li>ARM-QEMU, gcc 4.8.4, -O0 and -O3</li>
|
||
<li>X86-FreeBSD 10.3, clang 3.4.1, -O0 and -O3</li>
|
||
<li>TCC 0.9.26 (x86-64) (used as a proxy for <a
|
||
href="/years.html#2001_bellard">2001/bellard</a>)</li>
|
||
<li>UNIX V7 pcc (Johnson’s C compiler) on a <a
|
||
href="http://simh.trailing-edge.com/">simulated PDP-11/45</a> (see
|
||
spoiler for further detail)</li>
|
||
</ul>
|
||
<div style="margin-bottom:60em;margin-top:4em">
|
||
<strong>Spoiler below; scroll down.</strong>
|
||
</div>
|
||
<h3 id="spoiler">SPOILER:</h3>
|
||
<p>This started life as a personal challenge: write the shortest hex
|
||
dump utility in C.</p>
|
||
<p>The self-imposed ground rules in the hunt for shortest:</p>
|
||
<ul>
|
||
<li>The code has to output correctly.</li>
|
||
<li>No extraneous newlines, the code must be portable, and without
|
||
bypassing the solution using <code>execve(2)</code>, or functions built
|
||
upon it (<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">"hd"</span><span class="op">);}</span> <span class="co">// it's turtles all the way down!</span></span></code></pre></div>
|
||
<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"><</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">&=</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"><</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">>></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">>></span> <span class="dv">4</span><span class="op">),</span>L <span class="op">(</span>l<span class="op">&</span><span class="dv">15</span><span class="op">);</span>O<span class="op">&&</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>
|
||
<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">&=</span><span class="dv">15</span><span class="op">,</span>printf<span class="op">(</span><span class="st">"</span><span class="sc">%02x</span><span class="st"> "</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">&&</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"><(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">>></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><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">"</span><span class="sc">%02x</span><span class="st"> "</span><span class="op">,</span>l<span class="op">);</span>O<span class="op">></span><span class="dv">1</span><span class="op">&&</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"><(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">>></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">&</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">"</span><span class="sc">%02x</span><span class="st"> "</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></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">"</span><span class="sc">%02x</span><span class="st"> "</span><span class="op">,</span>l<span class="op">),-~</span>O<span class="op">&</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"><(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">>></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">&</span>printf<span class="op">(</span><span class="st">"</span><span class="sc">%02x</span><span class="st"> "</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"><(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">>></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"><(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">>></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>printf<span class="op">(</span><span class="st">"</span><span class="sc">%02x</span><span class="st"> "</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"><(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">>></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>printf<span class="op">(</span><span class="st">"</span><span class="sc">%02x</span><span class="st"> "</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"><(</span><span class="dv">4</span><span class="op">^</span>l<span class="op">>></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>printf<span class="op">(</span><span class="st">"</span><span class="sc">%02x</span><span class="st"> "</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>
|
||
<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"><</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">&</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">>></span><span class="dv">4</span><span class="op">),</span>O<span class="op">(</span>l<span class="op">&</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">"</span><span class="sc">%02x%c</span><span class="st">"</span><span class="op">,</span>l<span class="op">,++</span>O<span class="op">&</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">&</span><span class="dv">15</span><span class="op">&&</span>puts<span class="op">(</span><span class="st">""</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">"</span><span class="sc">%02x</span><span class="st"> "</span><span class="op">,</span>l<span class="op">),-~</span>O<span class="op">&</span><span class="dv">15</span><span class="op">:!</span>O<span class="op">)||</span>puts<span class="op">(</span><span class="st">""</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">&</span>printf<span class="op">(</span><span class="st">"</span><span class="sc">%02x</span><span class="st"> "</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">""</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">(&</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">&</span>printf<span class="op">(</span><span class="st">"</span><span class="sc">%02x</span><span class="st"> "</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>
|
||
<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">'\012'</span> <span class="op"><</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">'\012'</span> <span class="op"><</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">'\012'</span> <span class="op"><</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>
|
||
<p>An obfuscated hex dump has been done before: <a
|
||
href="/1986/bright/README.md">1986/bright</a> is similar in function,
|
||
but it uses more characters in just setting up its obfuscation than this
|
||
entire solution!</p>
|
||
<h3 id="bigger-spoiler">BIGGER SPOILER:</h3>
|
||
<p>If you are unhappy with the way DEL (character 127) is handled,
|
||
replace the cryptic expression <code>4<(4^l>>5)?l:46</code>
|
||
with <code>32>l|l>126?46:l</code>. Both take the same number of
|
||
characters, but the former is a bit more interesting. Bonus question:
|
||
how does the first expression work?</p>
|
||
<h3 id="biggest-spoiler-and-some-history">BIGGEST SPOILER (and some
|
||
history):</h3>
|
||
<p>Technically, <code>char o[0];</code> is illegal (SS 6.7.6.2)
|
||
according to ISO (N1570). And <code>char o[];</code> is a conditionally
|
||
supported feature (SS 6.7.6.2, 6.10.8.3). However, it works in modern C
|
||
implementations as an extension, including GCC, Clang and TCC, for X86
|
||
and ARM, on multiple operating systems (Linux, OSX/macOS, FreeBSD), so
|
||
it is <em>functionally</em> correct. MicroSoft Visual C++ does not allow
|
||
<code>char o[]</code> or <code>char o[0]</code>, and implements its
|
||
close relative <code>char o[1]</code> such that writing more than a
|
||
single char will cause a fault, which is <em>technically</em>
|
||
correct.</p>
|
||
<p>But how does this work at all, even as an extension? <code>o[]</code>
|
||
allocates one(!) byte in a zero-filled data area (formerly <a
|
||
href="https://en.wikipedia.org/wiki/.bss">BSS</a>). The UNIX-derived
|
||
systems this code was run upon all place the storage of <code>O</code>
|
||
and <code>o</code> into a zero-filled VM page with nothing following:
|
||
thus, there are plenty of available and unused zero bytes following
|
||
<code>O</code>, addressed via <code>o</code>, and this code only needs
|
||
17. This is <em>undefined</em> behavior, but as shown, it is widely
|
||
available.</p>
|
||
<p>The <a href="http://minnie.tuhs.org/cgi-bin/utree.pl">1979 Seventh
|
||
Edition UNIX</a> (v7) system pre-dates the IOCCC by several years, and
|
||
the source code to <code>sh</code>(1) was a <a
|
||
href="/all/README.md">significant inspiration for this contest</a>.
|
||
There are two C compilers present: <code>cc</code> written by Dennis
|
||
Ritchie, and <code>pcc</code> written by Steven Johnson. The nested
|
||
conditional expressions in 116 and smaller are too complex for
|
||
<code>cc</code> (“Illegal conditional”) but <code>pcc</code> handles
|
||
them correctly, and neither compiler accepts <code>char o[]</code> or
|
||
<code>char o[0]</code> and neither put the bytes in a zero-filled page
|
||
(as a paged VM was not yet written for UNIX).</p>
|
||
<p>More significant is that v7 <code>printf(3)</code> does not report
|
||
the number of characters written, and therefore 111 compiles but does
|
||
not work correctly; 113 is the shortest code that compiles and runs
|
||
correctly in Ancient UNIX.</p>
|
||
<p>Interesting digression: v7 <code>printf</code> (<code>_doprnt</code>)
|
||
was written in PDP-11 assembly. It pre-dates <code>varargs.h</code>, and
|
||
assembly was the only way to gain access to the variable argument types.
|
||
The first edition <em>The C Programming Language</em>, 1978, page 71,
|
||
remarks:</p>
|
||
<blockquote>
|
||
<p>By the way, there is no entirely satisfactory way to write a portable
|
||
function that accepts a variable number of arguments, because there is
|
||
no portable way for the called function to determine how many arguments
|
||
where actually passed to it in a given call. …<br />
|
||
<code>printf</code>, the most common C function with a variable number
|
||
of arguments, … is also non-portable and must be modified for different
|
||
environments.</p>
|
||
</blockquote>
|
||
<p>It is fascinating to explore the roots of C through the history of
|
||
the operating system it was birthed within. C is often criticized as a
|
||
difficult, inscrutable language, but as this contest demonstrates, this
|
||
is in parody. <em>Shell-gol</em> is one of those instances where someone
|
||
<a
|
||
href="https://web.archive.org/web/20180521074522/http://www.computerworld.com.au/article/279011/a-z_programming_languages_bourne_shell_sh/?pp=4">preferred
|
||
a different language</a>, and (ab)used the preprocessor to re-mold C
|
||
into something they found comfortable. Most of the rest of the system,
|
||
especially in the kernel, are models of clarity and efficient
|
||
expression.</p>
|
||
<h3 id="tldr">TL;DR:</h3>
|
||
<p>So which version is the shortest, portable hex dump?</p>
|
||
<ul>
|
||
<li>109 works with (most?) modern Unix-like systems and compilers, see
|
||
example list above.</li>
|
||
<li>111 works adds Microsoft, is standards-approved, and does not
|
||
exploit undefined behavior.</li>
|
||
<li>113 works on Ancient UNIX and the portable C compiler.</li>
|
||
<li>119 works on all platforms, including the original Ritchie PDP-11 C
|
||
compiler.</li>
|
||
</ul>
|
||
<h3 id="coda">Coda:</h3>
|
||
<p>Clearly, the smallest possible program violates modern best practice.
|
||
It is not even possible to compile cleanly, but it will compile
|
||
correctly.</p>
|
||
<p>Included is <a href="prog.alt.c">prog.alt.c</a>, a modern C
|
||
implementation that is – perhaps – the smallest, clean-compiling version
|
||
using <code>clang</code> or <code>gcc</code> with
|
||
<code>-Wall -pedantic</code>. Note that while this is larger than all
|
||
but the original 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>
|
||
<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>
|
||
<p>to compare the differences (<code>diff</code> is not helpful on a
|
||
one-liner).</p>
|
||
<h2 id="copyright-and-cc-by-sa-4.0-license">Copyright and CC BY-SA 4.0
|
||
License:</h2>
|
||
<p>This file is Copyright (c) 2023 by Landon Curt Noll. All Rights
|
||
Reserved. You are free to share and adapt this file under the terms of
|
||
this license:</p>
|
||
<pre><code>Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)</code></pre>
|
||
<p>For more information, see:
|
||
https://creativecommons.org/licenses/by-sa/4.0/</p>
|
||
|
||
<!-- END: this line ends content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||
<!-- START: this line starts content for HTML phase 22 by: bin/output-index-inventory.sh via bin/md2html.sh -->
|
||
|
||
<!-- START: this line starts content generated by: bin/output-index-inventory.sh -->
|
||
|
||
<h1 id="inventory-for-2018burton1"><a name="inventory"></a>Inventory for
|
||
2018/burton1</h1>
|
||
<h2 id="primary-files">Primary files</h2>
|
||
<ul>
|
||
<li><a href="index.html">index.html</a> - entry home page</li>
|
||
<li><a
|
||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2018/burton1/prog.c">prog.c</a>
|
||
- winning source</li>
|
||
<li><a
|
||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2018/burton1/Makefile">Makefile</a>
|
||
- entry Makefile</li>
|
||
<li><a
|
||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2018/burton1/prog.alt.c">prog.alt.c</a>
|
||
- alternative source</li>
|
||
<li><a
|
||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2018/burton1/prog.orig.c">prog.orig.c</a>
|
||
- original source</li>
|
||
<li><a
|
||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2018/burton1/scripthd.sh">scripthd.sh</a>
|
||
- driver program - adds several nice-to-have features</li>
|
||
<li><a
|
||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2018/burton1/try.sh">try.sh</a>
|
||
- how to run</li>
|
||
<li><a href="2018_burton1.tar.bz2">2018_burton1.tar.bz2</a> - download
|
||
winning source</li>
|
||
</ul>
|
||
<h2 id="secondary-files">Secondary files</h2>
|
||
<ul>
|
||
<li><a
|
||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2018/burton1/.entry.json">.entry.json</a>
|
||
- description of entry in JSON</li>
|
||
<li><a
|
||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2018/burton1/.gitignore">.gitignore</a>
|
||
- list of files that should not be committed under git</li>
|
||
<li><a href=".path">.path</a> - directory path from top directory</li>
|
||
<li><a
|
||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2018/burton1/README.md">README.md</a>
|
||
- markdown source for index.html</li>
|
||
</ul>
|
||
|
||
<!-- END: next line ends content generated by: bin/output-index-inventory.sh -->
|
||
|
||
<!-- END: this line ends content for HTML phase 22 by: bin/output-index-inventory.sh via bin/md2html.sh -->
|
||
<!-- START: this line starts content from: inc/after-content.default.html -->
|
||
|
||
<!-- END: this line ends content from: inc/after-content.default.html -->
|
||
<!-- START: this line starts content from: inc/end-rightcolumn.default.html -->
|
||
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/end-rightcolumn.default.html -->
|
||
<!-- START: this line starts content from: inc/end-row.default.html -->
|
||
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/end-row.default.html -->
|
||
<!-- START: this line starts content from: inc/footer.default.html -->
|
||
|
||
<div class="footer">
|
||
<hr>
|
||
<h2>Coda</h2>
|
||
<p><a href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fioccc-src.github.io%2Ftemp-test-ioccc%2F2018%2Fburton1%2Findex.html">Nu HTML check this web page</a></p>
|
||
<p><a href="#top">Jump to top</a> <a href="#content">Jump to Content</a> <a href="#inventory">Jump to Inventory</a></p>
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/footer.default.html -->
|
||
<!-- START: this line starts content from: inc/bottom.default.html -->
|
||
|
||
</body>
|
||
</html>
|
||
|
||
<!-- END: this line ends content from: inc/bottom.default.html -->
|