Remove hint.html and index.html

As per discussions on GitHub the index.html and hint.html files should
be deleted in favour of README.md files (from any
.text/.txt/.markdown/.md files which will be turned into README.md in an
upcoming commit).
This commit is contained in:
Cody Boone Ferguson committed 2023-02-08 05:07:05 -08:00
1 parent ee8a36310f
commit 77fb0f11a2
143 files changed
-28606

No files matched your search

-210
View File
@@ -1,210 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Most Useful</title>
</head>
<body>
<h1>Most Useful</h1>
<p>Dave Burton <a href="&#109;&#x61;&#105;&#108;&#116;&#x6f;&#58;&#x69;&#x6f;&#99;&#x63;&#x63;&#64;&#115;&#110;&#x6f;&#120;&#46;&#x6e;&#101;&#116;">&#105;&#x6f;&#99;&#99;&#x63;&#64;&#115;&#110;&#x6f;&#x78;&#46;&#110;&#x65;&#116;</a><br>
<a href="http://snox.net/ioccc">http://snox.net/ioccc</a></p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
./prog "expression"
</code></pre>
<p>or</p>
<pre><code>./prog
(input expressions)
</code></pre>
<h3>Try:</h3>
<pre><code>./prog '?0x3343&lt;&lt;2'
echo '?0x3343&lt;&lt;2' | ./prog
./prog
Enter:
a=0xfeedface
b=0xcafe
a &lt;&lt; 16 + b
grep '[0-9]' prog.c
./prog &lt; test.in
less calc.man
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>&ldquo;Look, Ma, no <del>hands</del> digits!&rdquo;</p>
<p>The place where some arithmetic operations are done, for example,
division or modulo, are easy to find. Where are addition and subtraction?</p>
<p>We were impressed with the level of detail the author &ldquo;blogged&rdquo; the obfuscation process.</p>
<h2>Author&rsquo;s comments:</h2>
<h2>calc - an integer expression calculator that outputs in both hex and decimal</h2>
<p>All useful tools should include sufficient documentation.
See the included man page. ;-)</p>
<h2>Notes</h2>
<p>This program is named calc. Onomatopoeia of sorts, in the visual realm.
The formatting was easier: Form Follows Function (although the 2011 <a href="/2011/hou/hint.html" title="Hou Qiming">Hou</a> entry
did this better).
It was tempting to call it iCalc, with i for integer (and it was written on an iDevice),
but sanity prevailed.</p>
<p>Printed in 8 pt Courier, it makes aesthetically pleasing 8.5 x 11 wall art.</p>
<h2>prog.c vs prog.orig.c</h2>
<p>Dominik Muth observed a syntax error on <code>1+1</code>, <code>1-1</code>, <code>1|1</code>, and <code>1^1</code> when using an
ARM based computer, although <code>1*1</code> and others worked correctly.
This occurs because some platforms by default treat <code>char</code> as <code>unsigned char</code>.
The original code has this weakness, which can be corrected by adding <code>-fsigned-char</code>
to the compile line.
The modified code is agnostic to <code>char</code> signed-ness.</p>
<h2>Why is this entry obfuscated/interesting?</h2>
<p>Yes, this is another calculator program.</p>
<p>However, unlike any other calculator source code the author is aware of,
this one contains no digits. At all. Anywhere. As in</p>
<pre><code>grep '[0-9]' prog.c || echo no digits!
</code></pre>
<p>Nor are the digits simply obfuscated. There are no character constants.
There is only one single, short string, and it does not contain any obfuscated digits.
And yet the output is in decimal and hexadecimal, and it accepts octal, decimal, and hex input.</p>
<p>Flow control is by <code>for</code> and <code>return</code>. It is If-less. Switch-less. While-less. Hope-less. <br>
Literally, if not figuratively. ;-)</p>
<p>The code size is intentionally 2015, as stated by iocccsize -i,
and can be reformatted without changes (as in rule2.c) to exactly 4096 octets.</p>
<p>Finally, calc is interesting, if for no other reason than it is practically useful:
Hex/decimal conversion, arithmetic, byte-swapping, bit-shifting, and logical operations with memory,
on the command line, or interactively.</p>
<h2>But the question is why is the entry obfuscated?</h2>
<p>The code follows many industry best-practices:</p>
<ul>
<li><p>You know what it does just by looking at it.</p></li>
<li><p>Numbers and digits have often been used for obfuscation,
so in a bid for better clarity, this code has no digits at all.</p></li>
<li><p>In the spirit of clarity, most of the variables are declared before use, so they
are readily visible, with single letter names that don&rsquo;t clutter the screen,
in a tautological arrangement.</p></li>
<li><p>More helpful is the use of <code>typedef</code>s instead of <code>#define</code>, so the types remain useful
even in the debugger, and source code beautifiers will not undo careful presentation.</p></li>
<li><p><code>#defines</code> are used here in the best spirit of the preprocessor: to shorten
repetitive constructs, not for obscurity.</p></li>
<li><p>All functions are short (and therefore easy to understand?) and do only one thing, well, &hellip;.</p></li>
<li><p>Curly braces invite endless holy wars over readability. This code only uses them
for function definitions, thereby greatly improving readability, and reducing arguments
about said readability.</p></li>
<li><p>One of C&rsquo;s many blessings (until recently) is a modicum of keywords,
of which only 8 are used:
<code>for</code>, <code>return</code>, <code>typedef</code>, <code>void</code>, <code>char</code>, <code>short</code>, <code>unsigned</code> and <code>long</code>;
10 if <code>#include</code> and <code>#define</code> are counted.</p></li>
<li><p>The code helpfully declares &ldquo;syntax_error!&rdquo; right up front, filling the reader with confidence.</p></li>
<li><p>In spite of its inherent clarity, the code was presented to both <em>indent</em>(1) and
<em>clang-format</em>(1), after running it through the preprocessor, sustaining its better qualities.</p></li>
<li><p>That the code is obfuscated is spelled out two different ways in the source; it helps
to reformat the code to see the second spelling.</p></li>
<li><p>The author is overly fond of the code that handles input.
There is no memory allocation, nor pre-allocation of arrays, so where does the
memory come from? The multi-base strtol() code is pretty trick.
No special attempt was made to replace operations with obscure mathematical relations,
as the (lack of) beauty is in the parsing &ndash; ask not where is the modulus operation,
but how does it know when to mod &ndash; okay, but where is add and subtract?
And really, who doesn&rsquo;t enjoy a setjmp() in the argument list?</p></li>
<li><p>Finally, documentation of the source code structure is helpfully provided in rot13 format.
But isn&rsquo;t it unsportsmanlike to rely upon it? However, even with this helpful guide,
things like reading input lines remain as tricky to read as they are to write.</p></li>
</ul>
<h2>Compiler warnings</h2>
<p>Calc is C99 compliant, and is ANSI/C90 compliant except for wanting 64-bit <code>long long</code>.
Changing the two <code>long long</code> typedefs to <code>long</code>, and compiling with <code>gcc -m32</code>
yields a program that operates on 32-bit values, with wrap-around of shifts mod 32:</p>
<pre><code>1&lt;&lt;48
65536 0x00010000
</code></pre>
<p>gcc 4.2.1 without arguments compiles cleanly (e.g. cc prog.c -o prog).
This is my workaday compiler. gcc is also clean with -ansi, and -std=c99.</p>
<p>clang 3.6.0 lives up to its namesake, resounding on non-problems.
To stifle these complaints:
-Wno-return-type -Wno-parentheses -Wno-empty-body</p>
<p>When invoked with -ansi -pedantic, there are two warnings, which can be ignored:</p>
<ul>
<li><code>ISO C90 does not support 'long long'</code></li>
</ul>
<p>With -Wall -std=c99, both are quite noisy, and all can be ignored:</p>
<ul>
<li><code>array subscript has type 'char' [-Wchar-subscripts]</code></li>
<li><code>value computed is not used [-Wunused-value]</code></li>
<li><code>operation on 'j' may be undefined [-Wsequence-point]</code></li>
</ul>
<h2>Test Suite</h2>
<p>If the program name begins with an &ldquo;e&rdquo;, it echoes stdin to stdout.
This allows for a convenient test suite:</p>
<pre><code>ln -s prog eprog
PATH=. eprog &lt; test.in | diff - test.out
</code></pre>
<h2>Spoilers</h2>
<p>If you do not want to puzzle out how it works, see spoilers.markdown.</p>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
-136
View File
@@ -1,136 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Most Crafty</title>
</head>
<body>
<h1>Most Crafty</h1>
<p>Gil Dogon<br>
<a href="http://sokoban-gild.com">http://sokoban-gild.com</a></p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
./prog
</code></pre>
<h3>Try:</h3>
<pre><code>./prog
press and hold the Left Arrow key until you turn 90-degrees to the left
when you see a long tunnel, press the function key F2
Use the Up, Down, Left and Right keys to change your path
Press function higher numbered function keys (F3, F4, ...) to go faster
Press F1 to stop
Turn 90-degrees to one side
Press F4 to and drill into some blocks for a bit
Press F1 to stop
Turn 180-degrees to face the way you came
Press F2 and navigate back down the new hole until you reach the long tunnel again
Press F1 to stop
etc.
Press the ESC key
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>You are in a twisty maze blocks, almost all alike.</p>
<p>Those blocks are generated by twisty maze of code blocks, almost all different.</p>
<p>Can you find your way around either and understand where you are?</p>
<p>How many function keys does your keyboard have? Can you generate very high number function keys such as F30 or F31? :-)</p>
<p><em>Textures? We don&rsquo;t need no stinking textures.</em></p>
<h2>Author&rsquo;s comments:</h2>
<h3>What is it?</h3>
<p>Just run prog with no arguments on an X11-compatible system. The scenery, though pseudo-randomly generated should be strangely familiar, specially to those still in their teen age. You can navigate using the keyboard arrow keys and the function keys. Your speed is a linear function of (n-1) where Fn is the last function key you have pressed, and you always move in the direction you are looking at. Be aware that you are probably some kind of a Creeper as is obvious from looking at the program, hence your movement is destructive to the environment. So after pressing F12 for warp speed, and moving around randomly, you might find yourself in a 3D maze of twisty little passages, from which there is only one Esc(ape) key. Note that in theory if you have a specialty keyboard with 32 function keys you may even press F31 to reach infinite improbability drive speed, though the author had never tested this feature. However a hidden comment in keysymdef.h suggests the existence of a mythical Sun Keyboard with 35 function keys :)</p>
<h3>Full disclosure.</h3>
<p>This entry, tough pretty thoroughly obfuscated, is not entirely original, nor am I Notch. The inspiration for this entry is a demo code written by the Notch himself, which was released with the following license: &ldquo;you may use the code in here for any purpose in any way you want, at your own risk&rdquo;. That version will henceforth be referred to as the original. Though the original in itself was quite nice and rather dense piece of code, it was not written in C, nor entirely and meticulously obfuscated, a state of things I hopefully rectified.</p>
<h3>Some extra features.</h3>
<p>Basing it on the original which already had a wonderful simple and concise ray casting through a generated voxel world rendering, I added a few tweaks of my own device:</p>
<ul>
<li>Two pass optimized rendering. The program first calculates 1/16 of the output image by ray casting, and then, when possible uses texture interpolation on the voxel faces. It speeds up the rendering by at least a factor of 4 on most scenes, but extra care must be taken when passing rays through the leaves voxels &hellip;</li>
<li>Fixed a small omission in the original. When you looked though a transparent leaves voxel, you did not see the leaves at voxel faces that were far from you. In this version the rendering of those (far face leaves) is correct.</li>
<li>Window rendering size specified in Makefile.</li>
<li>Added the keyboard controls for navigation (and destruction).</li>
</ul>
<h3>Portability issues.</h3>
<p>This entry is rather portable I think on modern platforms. It assumes of course basic X-windows availability. There are several other salient assumptions though:</p>
<ul>
<li>The entry assumes sizeof(int)=4. This seems to cover pretty much everything that supports X-windows so would be broken only on quite ancient machines, embedded processors, or some big iron 64 bit system where sizeof(int)=8.</li>
<li>The entry assumes the default visual has 24 bit depth (RGB). This seems to be the case on most X Servers this days.</li>
<li><p>The entry, does a thing which is an absolute No-No for X-windows program, i.e. assuming it knows some numeric values for keysyms defined in keysymdef.h . I have searched far and wide the lord Google&rsquo;s domain, yet was unable to find a version of the file where those assumptions were broken. This enables the important support of up to 32 function keys keyboards without spilling over the size limit, and allows us to use such fun expression for arrow view control as the following:</p>
<pre><code> *(a&amp;1?&amp;C:&amp;B)-=(.05 -a/2%2*.1)*!(a-1&amp;4092^3920)
</code></pre></li>
</ul>
<h3>Precision issues.</h3>
<p>The entry, on purpose, (see the section about SIMD below) does not use enough bits of precision, so some times the ray will miss the intersection of two voxel faces and push on through. That&rsquo;s why you may notice some noise along close up voxel edges. Fixing this issue would have taken the entry over the size limit regrettably.</p>
<h3>Obfuscations.</h3>
<p>Well, of course you have all the usual suspects, used for extreme compression, and such a nice layout: not very informative identifiers, which are being reused all over the place, some rather gruesome looking expressions, a whole load of magic constants with apparently no rhyme nor reason (including a Lagrange polynomial), and a message from our friendly Cetaceans. However it also includes some clever and not so obvious though instructive techniques, to subtly make the code more magical and efficient, at the same time.</p>
<p>Those techniques are about the use of 64 bit integers in order to do SIMD work, in a portable way without ever using any SSE/AVX or other non-portable compiler inline functions! The irony though, is that when compiling the program on modern X86 architectures indeed SSE/AVX is used for the long longs.
Following is some &ldquo;Spoiler&rdquo; information, So if you want to play tough, stop reading at this point.</p>
<h3>Portable SIMD programming.</h3>
<p>So how is this done? Quite simply by using the whole long long arithmetic&rsquo;s capability. I think the C99 standard assures us that long long has at least 64 bits. Most of those bits are unused in normal programs, however here we use them more wisely. For example, in the inner loop of the program you have the innocent looking expression i+=d. What it does in fact, is a SIMD addition of two vectors, each with three signed fixed point coordinates, advancing our ray in 3D space!
To spell it out, the macro producing such vectors is P, and the assignment q=0x820008202625a0 sets our creeper original position to about (32.5, 32.5019, 2441.406) .</p>
<p>Evidently when doing such arithmetics, care must me taken to avoid overflow from one component to the other, but since our voxel world is a torus of size 64 in each dimension this hardly matters. A subtle issue, is how to deal with signed quantities. In the i+=d expression above i has 3 positive components, but d has arbitrary signed components, as our ray may face in any direction. It seems things should not work, specially as we defined both i and d as unsigned! However notice that the T (and P )macro converts float to signed long longs. Once sign is extended from a least component into higher bits, it seems at first to be recipe for disaster, however everything works beautifully, and you get precise component results when the final accumulation components in i are positive. This only gets broken a bit when the final accumulation has a least significant negative component. To see this bug in action change the assignment above to q=0x82000820000000, and look towards the negative direction of the main tunnel.</p>
<p>Similar technique is used on the RGB components so their brightness can be adjusted simultaneously by the expression: o=o*b>>8 . Of course some spare bits are needed between the components, so they are spread in the long long and reordered as RBG.</p>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
-215
View File
@@ -1,215 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Best Handwriting</title>
</head>
<body>
<h1>Best Handwriting</h1>
<p>Etienne Duble <a href="&#109;&#x61;&#105;&#108;&#116;&#x6f;&#58;&#x65;&#x74;&#105;&#x65;&#x6e;&#110;&#101;&#46;&#x64;&#117;&#98;&#x6c;&#101;&#64;&#105;&#x6d;&#97;&#103;&#x2e;&#102;&#114;">&#101;&#x74;&#x69;&#101;&#110;&#x6e;&#101;&#46;&#100;&#x75;&#x62;&#108;&#x65;&#x40;&#x69;&#x6d;&#x61;&#103;&#46;&#x66;&#114;</a><br>
<a href="http://lig-membres.imag.fr/duble">http://lig-membres.imag.fr/duble</a></p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
echo Some text | ./prog
</code></pre>
<h3>Try:</h3>
<pre><code>echo Hello, world | ./prog
DRAFT=1 ./prog &lt; prog.c
./prog
&gt; [type]
(...observe...)
./prog &lt; prog.c
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>Beautiful penmanship! However, your fonts may vary.</p>
<p>How does this entry compress the font it uses? What&rsquo;s the purpose of lrand48()?
Why does the program dump core, when it does :) ?</p>
<h2>Author&rsquo;s comments:</h2>
<h3>Introduction</h3>
<p>This program <strong>prints text in your terminal with an interesting
hand-writing effect</strong>.</p>
<p>It uses the <em>braille patterns</em> range of the unicode standard: this
allows to consider each terminal character as a tiny 2x4 bitmap.</p>
<p>Turning the Braille code into something visual might be considered
blasphemous. When I was fighting to make this program work, I started
wondering if it was not the reason for its very erratic behaviour.</p>
<h3>prog.c vs prog.orig.c</h3>
<p>The file <code>prog.orig.c</code> is the one I submitted.</p>
<p>Gil Dogon noted a few unsafe statements (statements whose behaviour is
undefined in the C standard and, as such, could cause issues with other
compilers or optimization levels). These have been fixed in <code>prog.c</code>.
After this fix, in order to remain rule-2-compliant, a variable name has
also been shortened in this file.</p>
<h3>How to build</h3>
<p>If you have <code>clang</code>:</p>
<pre><code>$ CC=clang make -e
</code></pre>
<p>Otherwise (gcc):</p>
<pre><code>$ make
</code></pre>
<p>(You will get a few warnings in this case.)</p>
<h3>How to use it</h3>
<p>You need a terminal configured to handle an <em>UTF-8</em> encoding and a
font including <em>braille patterns</em>.
This is the default on most modern GNU/Linux operating systems.
The default terminal application (gnome-terminal) or even a simple
xterm should render things properly.
I tested this on several Debian and Ubuntu systems, 32 and 64bits (no configuration was needed).
I also tested it on FreeBSD 9.3 32bits (font and encoding configuration
was needed in this case).</p>
<p>Basic mode:</p>
<pre><code>$ echo 'I am testing this thing.' | ./prog
[... rendering ...]
$ ./prog &lt; lorem-ipsum.txt
[... rendering ...]
</code></pre>
<p>Interactive mode:</p>
<pre><code>$ ./prog
&gt; hello world!!!
[... rendering ...]
&gt;
</code></pre>
<h3>Obfuscation</h3>
<p>This entry is obfuscated in various ways:</p>
<ul>
<li>The structure is hidden by avoiding loops, &lsquo;if&rsquo; statements, ternary
conditionals, and jump-related instructions. Instead, recursivity is
heavily used.</li>
<li>Merging all functions into one added even more recursivity. ;)</li>
<li>The provided code does not contain the same number of opening and closing
parenthesis.</li>
<li>Preprocessing the code inflates it and adds lots of indents. Removing some
of the tricks involved without breaking the program will be challenging.</li>
<li>The program &lsquo;plays&rsquo; with standard input &amp; output streams, which causes
unusual side effects.</li>
<li>Some variables are re-used for unrelated processings.</li>
<li>Crucial data may be hidden in unexpected places (e.g. as the size of
a temporary buffer).</li>
<li>Some parts of the code may have no effect (but may have an effect in a
specific context, who knows?), and classical libc functions may not act
as usual.</li>
<li>And of course variable names are hard to read (or distracting).</li>
</ul>
<p>On the other hand, the following may help:</p>
<ul>
<li>The code layout should help to identify which part of the code is
obfuscated. ;)</li>
<li>File &lsquo;codes.txt&rsquo; shows how each character is drawn. This data is
encoded in macro O_o at the top of the source file.</li>
</ul>
<h3>Limitations</h3>
<h4>Charset</h4>
<p>In order to comply with the size rule, I encoded only a part of the visible ASCII
chars:</p>
<pre><code>a-z, A-Z, '.' ':' ',' ';' '!' and '?'.
</code></pre>
<p>Uppercase and lowercase chars are rendered the same.
The program also understand the space and the linefeed (\n).
Other chars are simply ignored (most of the time ;)</p>
<h4>Stack size</h4>
<p>This limitation is due to the heavy use of recursivity. After having processed
a large number of characters, the process may exceed the stack size and crash.
(However I did not experience this myself. The top-level recursion might be
removed by the compiler as part of its optimizations.)</p>
<h4>Line rendering</h4>
<p>The program does its best to avoid cutting words at the end of lines, but
it could still happen in case of long words.</p>
<h3>Subtleties and extra features</h3>
<h4>Handling more than text docs?</h4>
<p>Given the limited set of characters handled, the program is mostly limited
to simple text documents.
Thus, if you try for example:</p>
<pre><code>$ ./prog &lt; prog.c
</code></pre>
<p>You will not get something that looks like C code. (but you can still try,
if you are curious. :)</p>
<h4>A &lsquo;draft&rsquo; mode</h4>
<p>Defining an environment variable called DRAFT will enable the &lsquo;draft-mode&rsquo;.
Try for example:</p>
<pre><code>$ echo 'testing the draft mode' | DRAFT=1 ./prog
</code></pre>
<p>The program will run much faster but the rendering will be less precise.</p>
<h4>The subtle interactive mode</h4>
<p>I saved the best for last: usually, programs that handle an &ldquo;interactive
mode&rdquo; have to check whether their standard input is a terminal or not (by
using isatty()). Did you notice that this program does not perform any such
detection, but still behaves (or seems to behave) appropriately?</p>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
-201
View File
@@ -1,201 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Most Diffused Reaction</title>
</head>
<body>
<h1>Most Diffused Reaction</h1>
<p>Someone Anonymous<br>
Twitter: @hirekoke</p>
<p>Yusuke Endoh<br>
<a href="https://github.com/mame/">https://github.com/mame/</a><br>
Twitter: @mametter</p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
&lt;tbd-tool-rubl-perl-python?&gt;
</code></pre>
<h3>Try:</h3>
<pre><code>Connect to port http://localhost:10333 with your browser
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>How did the leopard get its spots? Why are a zebra&rsquo;s stripes unique?</p>
<p>In case you didn&rsquo;t recognise the portrait of Alan Turing, there are some
pointers to his features like eyes with &ldquo;stdeye-o&rdquo; and &ldquo;&lt;&ndash;mouth&rdquo;. Can you
find any other tributes?</p>
<h2>Author&rsquo;s comments:</h2>
<p>What does &ldquo;Alan Turing&rdquo; remind you of? Cryptanalysis of the Enigma? Turing machine? Turing test? This program is also based on his work.</p>
<h3>Whirlwind tour</h3>
<p>Compile the program as follows:</p>
<pre><code>$ clang -O3 -std=c99 \
-Wall -Wextra -pedantic -o prog prog.c \
-Delta_u="Du*laplacian(u)-u*v*v+F*(1-u)" \
-Delta_v="Dv*laplacian(v)+u*v*v-v*(F+K)" \
-DF=0.040 -DK=0.060 -DDu=0.200 -DDv=0.100 \
-DUV_BACKGROUND=1,0 -DUV_DROP=-0.5,0.5 \
-DTIMESTEP=1.0 -DSPEED=2 -DRGB=255:128:192
</code></pre>
<p>Then, run it under <code>tcpserver</code> command in <a href="http://cr.yp.to/ucspi-tcp.html">ucspi-tcp</a> package, which was created by Daniel J. Bernstein, IOCCC 1989 &ldquo;Best of Show&rdquo; winner.</p>
<pre><code>$ tcpserver -v 127.0.0.1 10333 ./prog ioccc.txt
</code></pre>
<p>Finally, open <code>http://127.0.0.1:10333/</code> by a modern browser supporting HTML5. You can use the mouse cursor to place drops into the Petri dish interactively.</p>
<h3>Description</h3>
<p>This is a simulator of <em>reaction-diffusion systems</em>.</p>
<p>Reaction-diffusion systems, proposed by Alan Turing in [1], are mathematical models in which two chemical substances are transformed into each other (<em>local chemical reactions</em>) and spread out (<em>diffusion</em>). Their interactions sometimes form non-trivial patterns, such as spots, spiral, dappling, and labyrinths.</p>
<p>The systems are generally formulated as follows:</p>
<pre><code>du/dt = F(u, v) + Du * laplacian(u)
dv/dt = G(u, v) + Dv * laplacian(v)
</code></pre>
<p>The functions <code>F(u, v)</code> and <code>G(u, v)</code> represent reactions of each substance, and the parameters <code>Du</code> and <code>Dv</code> are diffusion coefficients. By changing the functions and parameters, you can see a wide range of behaviors.</p>
<p>See <a href="https://en.wikipedia.org/wiki/Reaction%E2%80%93diffusion_system">the Wikipedia article of &ldquo;Reaction-diffusion system&rdquo;</a> in detail.</p>
<p>This program simulates the systems. The field consists of 128 x 128 cells. Each cell includes infomration of an amount of the two substances, and interacts with neighbor cells (in terms of von Neumann neighborhood) in each frame.</p>
<h3>Configuration</h3>
<p>You can change the model, initial pattern, simulation speed, and color via macro definition.</p>
<h4>Model: <code>-Delta_u=&lt;expression&gt; -Delta_v=&lt;expression&gt;</code></h4>
<p>The definitions represent the equations of reaction-diffusion system. For example, the following is <a href="http://groups.csail.mit.edu/mac/projects/amorphous/GrayScott/">the Gray-Scott model</a> in TeX notation.</p>
<pre><code>\frac{\partial u}{\partial t} = D_u \Delta u - u v^2 + F (1 - u)
\frac{\partial v}{\partial t} = D_v \Delta v + u v^2 - v (F + K)
</code></pre>
<p>You can specify this model as follows:</p>
<pre><code>-Delta_u="Du*laplacian(u)-u*v*v+F*(1-u)" \
-Delta_v="Dv*laplacian(v)+u*v*v-v*(F+K)"
</code></pre>
<p><code>Du</code>, <code>Dv</code>, <code>F</code>, and <code>K</code> are parameters of that model.</p>
<h4>Initial pattern: <code>-DUV_BACKGROUND=&lt;u0&gt;,&lt;v0&gt; -DUV_DROP=&lt;u1&gt;,&lt;v1&gt;</code></h4>
<p>The definitions specifies the initial amount of the two substances u and v. All cells have <code>(u0, v0)</code> by default.</p>
<p>You can specify a pattern file when the executable is invoked (not compile-time). The file should include a sequence of points, see <code>ioccc.txt</code>, <code>center.txt</code>, or <code>line.txt</code> as examples. Each amount in cells near to the point included in the file, will be added by <code>(u1, v1)</code>.</p>
<h4>Simulation speed: <code>-DTIMESTEP=ts -DSPEED=spd</code></h4>
<p>The definitions are for changing the simulation speed.</p>
<p><code>TIMESTEP</code> is a simulation time step. The bigger, the faster but more unstable.</p>
<p><code>SPEED</code> is a frameskip parameter. The bigger, the faster but more sluggish.</p>
<h4>Rendering color: <code>-DRGB=r:g:b</code></h4>
<p>This specifies a color used for rendering.</p>
<h3>Examples</h3>
<p>Some interesting parameters are included in <code>Makefile</code>. Do one of the following command and open <code>http://127.0.0.1:10333</code>.</p>
<pre><code>$ make gray-scott-1 &amp;&amp; tcpserver -v 127.0.0.1 10333 ./gray-scott-1 ioccc.txt
$ make gray-scott-1 &amp;&amp; tcpserver -v 127.0.0.1 10333 ./gray-scott-1 center.txt
$ make gray-scott-1 &amp;&amp; tcpserver -v 127.0.0.1 10333 ./gray-scott-1 line.txt
$ make gray-scott-2 &amp;&amp; tcpserver -v 127.0.0.1 10333 ./gray-scott-2 ioccc.txt
$ make gray-scott-3 &amp;&amp; tcpserver -v 127.0.0.1 10333 ./gray-scott-3 ioccc.txt
$ make gray-scott-4 &amp;&amp; tcpserver -v 127.0.0.1 10333 ./gray-scott-4 ioccc.txt
$ make fitzhugh-nagumo-1 &amp;&amp; tcpserver -v 127.0.0.1 10333 ./fitzhugh-nagumo-1 ioccc.txt
$ make fitzhugh-nagumo-2 &amp;&amp; tcpserver -v 127.0.0.1 10333 ./fitzhugh-nagumo-2 ioccc.txt
$ make oregonator &amp;&amp; tcpserver -v 127.0.0.1 10333 ./oregonator ioccc.txt
</code></pre>
<p>These examples are created by drawing (and modifying) the pattern files of <a href="https://github.com/GollyGang/ready">Ready</a>, a cross-platform implementation of various reaction-diffusion systems [2].</p>
<h3>Compatibility</h3>
<h4>C part</h4>
<p>This program compiles clean with no warnings under <code>-std=c99 -Wall -Wextra -pedantic</code>. Since it uses <code>long long</code> for 64bit integers, C99 is required.</p>
<h4>Browser part</h4>
<p>You must use a modern browser that supports the latest specification of WebSocket [3]. All the following browsers worked for me:</p>
<ul>
<li>Google Chrome 45</li>
<li>Mozilla Firefox 39</li>
<li>Microsoft Internet Explorer 11 (works but sluggish)</li>
</ul>
<p>I think Safari 6 will work but I haven&rsquo;t tested. (I have no recent os x.)</p>
<h4>tcpserver alternatives</h4>
<p>I think you may use <code>inetd</code> and <code>xinetd</code> instead of <code>tcpserver</code>. Here is an example of inetd configuration.</p>
<pre><code>10333 stream tcp nowait nobody /path/to/prog /path/to/prog /path/to/initial-pattern.txt
</code></pre>
<p>But note that I didn&rsquo;t test well.</p>
<h3>Internal</h3>
<ol>
<li>The C program accepts HTTP connection from the browser, and sends a HTML document.</li>
<li>The browser tries to upgrade the connection to WebSocket.</li>
<li>The C program accepts WebSocket upgrade. This negotiation process requires SHA1 hash [4] and Base64 encoding [5]. The C program calculates them without the aid of any external libraries.</li>
<li>The C program simulates the reaction-diffusion system, and then send the field data to the browser on each frame.</li>
<li>The browser receives and renders the field data onto the HTML5 canvas.</li>
</ol>
<h3>References</h3>
<ul>
<li>[1] Turing, A. M., &ldquo;The Chemical Basis of Morphogenesis&rdquo;, Philosophical Transactions of the Royal Society, 1952.</li>
<li>[2] The Ready Bunch, &ldquo;Ready&rdquo;, A cross-platform implementation of various reaction-diffusion systems, since 2011, <a href="https://github.com/GollyGang/ready">https://github.com/GollyGang/ready</a>.</li>
<li>[3] Fette, I. and A. Melnikov, &ldquo;The WebSocket Protocol&rdquo;, RFC 6455, DOI 10.17487/RFC6455, December 2011, <a href="http://www.rfc-editor.org/info/rfc6455">http://www.rfc-editor.org/info/rfc6455</a>.</li>
<li>[4] Eastlake 3rd, D. and P. Jones, &ldquo;US Secure Hash Algorithm 1 (SHA1)&rdquo;, RFC 3174, DOI 10.17487/RFC3174, September 2001, <a href="http://www.rfc-editor.org/info/rfc3174">http://www.rfc-editor.org/info/rfc3174</a>.</li>
<li>[5] Josefsson, S., &ldquo;The Base16, Base32, and Base64 Data Encodings&rdquo;, RFC 4648, DOI 10.17487/RFC4648, October 2006, <a href="http://www.rfc-editor.org/info/rfc4648">http://www.rfc-editor.org/info/rfc4648</a>.</li>
</ul>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
-88
View File
@@ -1,88 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Most Overlooked Obfuscation</title>
</head>
<body>
<h1>Most Overlooked Obfuscation</h1>
<p>Yusuke Endoh<br>
<a href="https://github.com/mame/">https://github.com/mame/</a><br>
Twitter: @mametter</p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
./prog
</code></pre>
<h3>Try:</h3>
<pre><code>cat prog.c
./prog | diff - prog.c
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>At this point you might be wondering, <a href="http://acronyms.thefreedictionary.com/WTF">WTF</a>?*</p>
<pre><code>* What The Freak (polite form)
* What's This For? (you may be wondering)
* What the Fish (python form)
</code></pre>
<p>How is this code obfuscated? Well look again:</p>
<pre><code>less prog.c
more prog.c
</code></pre>
<p>Where did those underscores come from? Well <a href="http://acronyms.thefreedictionary.com/RTFS">RTFS</a>!**</p>
<pre><code>** Read the Freaking Source (polite form)
** Read The Freakin' Screen (polite form)
</code></pre>
<p>If you are still puzzled, look at prog.c with your favorite text editor.</p>
<h2>Author&rsquo;s comments:</h2>
<p><strong>Follow this instruction literally!</strong></p>
<pre><code>cat prog.c
gcc -w -o prog prog.c
./prog
</code></pre>
<p>You will do a double take.</p>
<p>Hint 1: Do <code>less prog.c</code>. You will see an <strong>emphasized</strong> string if your terminal supports bold.</p>
<p>Hint 2: Do <code>wc -c prog.c</code>. This is very long one-liner.</p>
<p>Spoiler: Open the source with an editor like <code>vim</code> or <code>emacs</code>.</p>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
-234
View File
@@ -1,234 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Back to the Future Award</title>
</head>
<body>
<h1>Back to the Future Award</h1>
<p>Yusuke Endoh<br>
<a href="https://github.com/mame/">https://github.com/mame/</a><br>
Twitter: @mametter</p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
./prog
</code></pre>
<h3>Try:</h3>
<pre><code>make -B BACK_TO=ioccc.c
./prog
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>Like Marty and Doc, something nostalgic from 1984 appears live in October of 2015!
The author of this gem is a true Delorean!</p>
<p>A question for inquisitive readers: is the implemented subset of PDP-11 instructions Turing-complete?
(For a clue, see the end of the author&rsquo;s remarks.)
If in doubt, use <a href="http://www.tuhs.org/Archive/PDP-11/Emulators/Apout/">APOUT</a>.</p>
<h2>Author&rsquo;s comments:</h2>
<h3>Hint / Compatibility</h3>
<ul>
<li>A little-endian system is required due to an external factor.</li>
<li>Strictly speaking, this program does not comply with any C specification for the same reason. But I believe it is reasonably portable.</li>
<li>It uses a GCC extension but works on clang.</li>
<li>This is a kind of emulator. You may find its architecture name if you look at the source code from all angles.</li>
<li>Find main() function.</li>
</ul>
<h3>Spoiler</h3>
<p>This program is a joke PDP-11 emulator. (&ldquo;ll-dpd&rdquo; is embedded in the code. Read it upside down.)</p>
<p>You got it? This program is supposed to be used in this way:</p>
<pre><code>$ wget http://ioccc.org/1984/mullender.c
$ clang -o prog prog.c mullender.c
$ ./prog
</code></pre>
<p>You can enjoy the legendary winner of the first IOCCC, again.</p>
<h3>Internal</h3>
<p>This program uses <code>__attribute__((constructor))</code>, which is a GCC extension, to hijack the main function call. And then it interprets main as an instruction sequence.</p>
<p>It supports the minimal subset of instructions and addressing modes which are needed for mullender.c to work:</p>
<ul>
<li><p>Instructions</p>
<ul>
<li>BR: branch</li>
<li>MOV: move</li>
<li>SOB: subtract one and branch</li>
<li>SUB: subtract</li>
<li>TRAP 4: write syscall</li>
<li>TST: test (no flag is supported, though)</li>
</ul>
</li>
<li><p>Addressing modes</p>
<ul>
<li>0: Register</li>
<li>1: Register deferred</li>
<li>2: Autoincrement</li>
<li>4: Autodecrement deferred</li>
<li>6: Index (incomplete)</li>
</ul>
</li>
</ul>
<h3>Limitation</h3>
<p>Non-trivial combination of instruction and addressing mode may cause undefined behavior (unsequenced modification), such as attempting to autoincrement a destination register. Index addressing mode works well only for R7 (PC register).</p>
<h3>One more thing</h3>
<p>Note: the program writes a binary to stdout.</p>
<pre><code>short main[]={5568,1,-30460,12,2782,0,-29921,2056,-4864,6873,770,30054,11886,
24948,114,21716,-28851,14043,-8944,32691,-16187,-12247,22692,-9781,-20403,
-11771,16546,18710,17873,9233,31304,-32215,-24382,-28247,-25916,10466,24988,
-3404,-4177,-28528,-531,-3016,17300,-28552,-7708,-26180,-4297,-367,-2312,
-25611,28535,-8533,24004,25421,-1224,-5354,-20807,-21589,-6761,-5203,-1055,
-6715,-26673,-1433,-17732,-24198,14681,-3714,-6660,-14891,-25575,20349,-7701,
-8336,31433,16695,-14773,26819,3096,-12584,-28808,17825,-21200,-32399,15877,
-28890,-3728,-27126,21375,-32630,-7615,32004,-29230,-6611,-5508,-28921,12418,
27204,-5725,9643,3520,26836,-29347,2101,-29311,9320,29287,-29990,-6593,29825,
-29114,16232,25641,20672,-23501,-32127,-6546,-956,10474,-29647,1070,5516,13760,
-27814,-32488,-28006,-17968,-3146,10963,19234,22132,23988,7142,5523,9639,-6888,
-11428,7964,23099,-16822,16518,31109,-12958,10351,2434,3091,3625,2244,27512,
-28559,-10724,-19377,23625,30056,11478,-21176,27660,26517,-29037,-9390,12297,
-11903,5980,-21927,-7483,6671,11249,29638,-23827,-26358,-6856,-1063,-5303,
26636,25797,31818,26798,-4243,-18772,-13266,27472,-12005,-10642,-22524,24373,
-13111,-9062,6274,-20002,24150,22189,-14965,-31249,-13934,-6341,-18384,-32054,
-29246,10622,-9260,19428,-15485,2724,23810,16447,11627,18604,2739,27812,30295,
-21538,-31786,11355,-11308,-9006,-4987,25363,-18927,-21130,-31213,-27411,17231,
-19608,20232,27754,16476,11213,-19803,-24048,30918,-25329,21233,-10160,13519,
11828,26653,-6703,10893,6871,-12417,24471,20310,-12137,-19677,4457,-19530,
10147,17724,533,-10055,27076,10264,11274,-10511,4809,25208,16065,-5105,-19953,
3772,-12124,13475,-27559,-9955,26446,15133,15207,-23640,6425,-11010,28688,
-20064,26353,-889,-25008,10380,-14449,-6894,18920,-23900,16902,-31018,16093,
20875,-19576,4585,13126,18589,24789,19424,31274,-5059,-14538,-3125,-16527,
-25070,-9013,26628,15756,-7652,30841,-1283,17707,25717,-18315,-6342,6880,
-19176,6995,5672,2853,-9044,-3409,-14421,-7522,13108,20582,-25317,1376,-5648,
13821,17300,1220,-29437,-25832,-8332,-15575,-9744,28297,31995,-1217,23852,
14382,31059,9160,-3296,20287,-28357,24449,-10323,-21992,-4655,-32548,13237,
-15083,-25226,-21121,2015,-8996,-20247,-27551,-14771,-16089,-6920,-9645,21578,
7142,-5613,14029,24730,-29253,13931,-3862,-16634,-7388,16951,15771,31302,
-22186,-6716,18416,1698,-26200,-16231,9821,-10886,-4994,-30527,-9448,-16923,
29549,-11207,-14909,-3643,-27548,17865,28859,29753,17616,16874,-17733,9424,
21435,-31715,24544,8666,30844,25075,-18267,12027,-5346,2717,19615,-4548,-21763,
28514,11691,22268,-2338,1406,-27379,-23568,-24525,13633,11295,-14715,7877,
-27669,3475,20345,7779,-17849,2184,7132,4079,-24937,11585,22740,5810,-10855,
16203,-6371,23235,-7,-24828,-11205,-11006,-10,-17812,-14274,11504,-27517,463,
4498,-32180,-9775,-3190,-22435,-18662,-30146,-31834,-26449,-19374,-12616,
-10596,14341,-10089,-18449,-16535,21439,21191,-1651,7695,-30009,-23339,-8675,
-20774,21588,-2793,8218,-14337,-10866,14060,-15343,31712,25247,-8539,18074,
-28683,-7363,-7663,-3563,-30718,17771,28687,-30495,30584,14022,-28053,5292,
-31576,-32486,-15470,-1330,23551,-2185,-10829,-13216,-4825,-2964,-14668,24559,
-4930,23731,-1152,-11493,-2321,15987,-27073,-20305,-24065,-25048,32750,-27440,
-1169,-25633,-4356,-24993,30439,-17165,-4580,8662,22655,-4588,-6162,-3122,
31986,-2569,20371,-12320,-25613,-16133,-25644,23677,12254,5855,26325,-13425,
-15903,-1930,-28488,31222,31153,17607,-2758,7594,-8868,30434,-2518,27956,
-19424,7370,6199,-17602,17347,-14358,25588,11611,-25209,-23701,-27444,-29788,
2680,-27406,9318,22483,-28356,28482,4577,-14891,17323,-30152,2507,2977,5004,
-11696,-31623,-15149,13357,28938,-14048,19490,-19860,-26050,10842,-24922,
-20986,8847,-31184,28519,-29168,32195,10516,25713,-3493,670,31283,-12769,
-17461,11357,13180,26133,15944,18051,-32167,-27990,16813,17676,21787,-17578,
11173,19093,2836,656,-15239,4632,23937,4106,-21655,-7494,-21575,-17647,-18465,
-14654,-29990,-10707,-12440,21465,5822,26164,-1404,-14303,-26635,-6900,-23611,
11998,-18551,971,27579,13325,4579,23059,29281,22291,29880,-17546,25664,-14990,
-526,-35,28218,-3214,11965,11263,6633,30719,32400,-29,-3733,24383,32678,-27542,
-4444,6196,5975,-19722,11902,16840,-11680,11146,-26391,-8980,21573,-9043,2349,
-12887,5916,-2996,10410,-23374,26338,11867,-14518,18281,14450,-5815,13842,359,
25450,27043,3355,13423,-20880,-26311,-30720,-2503,-6046,-18156,-18558,-14774,
-15664,-29001,3365,-12689,10233,23608,24692,12039,15445,18411,-27469,3764,
-10841,22672,23844,2282,-12443,2851,-27163,13651,13738,17201,-29819,27414,
-29764,-5308,-16171,-32427,-26312,-7460,-27376,-6004,25717,29254,-15015,8754,
15493,22232,-28513,-23355,23676,7736,10571,-8120,-16677,7696,32549,-2646,25538,
3498,30960,-28459,24716,12655,-10496,402,26209,482,-16661,-20350,-3403,14015,
32299,11262,-25886,4092,-7843,-100,-1975,-58,-3729,-19269,-23583,-6929,20000,
-6089,17780,-3250,29830,19954,-29277,27896,10330,9277,-25358,31279,-14454,
24203,-30170,12872,-21973,-25773,-10502,-6647,-26143,6394,-13479,-24559,23007,
-21844,1505,24702,-23187,-24364,-20470,20765,-7107,15674,9404,17408,17964,
19820,18952,2154,-26052,30056,-3227,17770,-8557,-31018,-27700,-25974,9003,
18218,22730,-19981,6737,3532,1562,-23626,14990,28472,-5270,17358,-32204,-29197,
-3647,4296,8588,25302,-23906,30328,-29119,-24392,8992,-16557,31530,-31216,
14107,13041,-6976,7529,-8296,17865,-1462,8181,-21588,-131,-10177,-25931,-14627,
8301,3708,-32097,20808,13892,-21179,1192,20853,3249,-8774,20843,3520,24954,
-14215,-25170,-16170,2390,25964,-23923,-17464,-7177,-27568,-9880,-4647,-7323,
15388,2113,-12338,-7737,26255,26818,-22156,-19610,-911,-17057,-556,29935,27647,
31806,23676,-18132,-19234,-10869,-3715,24983,-10900,-29564,19856,-16392,-31860,
-25826,24077,12080,15383,-29852,-2266,-27217,31931,-3183,17385,-14211,19050,
-2449,-468,-2871,-11466,973,2866,649,1367,-8688,-24069,20992,25139,-25850,1184,
15851,785,16951,12160,22337,-21851,1849,-18801,14247,-429,-12682,30881,-11273,
-24819,-9794,8389,-27287,7525,16633,1328,-26650,32607,-8217,31912,7774,-16188,
-3546,-6550,-16279,-32696,1940,2577,-23723,-6484,2009,-424,27833,-21763,-13902,
7044,27360,-18450,27889,23987,3137,-7669,-5784,-7490,24946,32302,26464,-15513,
28898,2493,-17645,-4615,-13434,-20884,-4058,-29951,-22281,24784,21083,-8536,
22147,-11261,-15069,20659,2993,19029,21909,6748,-3263,1401,30960,11000,-16871,
-30566,-14959,-26356,-2885,21526,-26531,31063,12857,4992,-5067,3130,-17602,
-1732,-6593,30200,24679,3267,310,20733,24863,-15669,7875,-4577,-13821,-22325,
15548,29744,3733,-14547,21459,22122,3854,-2572,30197,-24770,-21263,8793,-8316,
1571,28191,-16143,-6446,31524,-26496,-17349,-29097,2806,11281,-7041,-683,14149,
19689,-22094,-1657,-30904,183,-15226,-6358,25461,461,1495,28345,-10554,-4004,
27119,13484,-21600,-12272,-7272,-14064,-299,10697,11280,19066,-9841,-7265,
-18002,19906,-17247,21482,-10939,-5897,-22300,-13978,27575,-8684,-6222,-19041,
5788,-30863,-10134,15142,2895,14705,-17713,12940,-21535,-11619,29416,18417,
-24973,24867,-26462,-24910,-32556,-26705,-7187,-7750,-758,-14809,20289,9260,
13778,-1422,30301,-1922,30646,27662,-15465,-912,29340,13846,-1263,28887,-20019,
32421,-29411,-27632,-7495,-8368,29230,-6386,-19536,-5235,2054,1854,23563,12348,
-15165,-2936,-28063,-15760,20126,-25531,4963,-5739,23182,16895,-17258,-10470,
-3969,-7742,-140,4475,-24014,-31961,19231,27153,-18551,20157,26443,11530,
-22214,2284,-24238,-31051,-26422,9088,29868,18458,8488,-9515,6799,-12507,54,
-19441,-32665,12561,23560,4725,-28617,-14800,-10224,-13503,-17636,-16823,
-24072,18735,-29798,-23658,-670,-21769,7489,-6468,-8961,-14785,22255,11582,
-29831,16303,-19652,2922,-4362,22966,16173,-18446,-6148,27381,-8493,-32289,
24005,-3027,-18665,-16472,-17793,-27027,-7443,17854,31365,-17726,-2510,-17546,
14893,21773,-23634,21117,32533,6637,-1106,-8152,-3672,-113,-2149,-34,-22700,
-4102,-28533,-14104,-10086,4378,13695,-15320,-28258,2246,7595,30021,13281,
-11968,-29983,14274,27152,26713,19434,17058,1142,-3043,-16496,18630,-11976,
29168,-3634,32746,27287,-268,16711,-8712,-471,12895,17406,-22548,-3969,-10733,
13128,10530,-31667,7929,-32277,30926,-1983,8401,-7705,6790,4532,1442,26728,
29600,-15358,21622,9744,11406,15989,-30741,-15044,29913,24534,6774,-3755,17623,
19647,18762,10042,9653,-5889,2408,-32579,-6285,-28559,-30655,6294,-21175,4390,
1668,25437,2821,21066,-13680,5274,-27253,-5248,-26307,29744,-26428,25358,17196,
15199,-29784,-4604,25653,-8048,-23131,-28995,31340,-9558,26186,11268,27916,
9646,-7389,-11384,-29116,-4100,160,18394,7856,738,-25920,12148,24713,-31664,
8203,-25556,13494,30352,29161,30898,1432,-5991,25411,1344,-4019,22299,15685,
-16401,-23136,-28110,11874,-18945,1879,2,0,-32256,-20996,-18169,29220,12,0,0,0,
335,-27277,-30776,20480,0};
</code></pre>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
-74
View File
@@ -1,74 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Best One-liner</title>
</head>
<body>
<h1>Best One-liner</h1>
<p>Yusuke Endoh<br>
<a href="https://github.com/mame/">https://github.com/mame/</a><br>
Twitter: @mametter</p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
./prog &lt;a number of arguments&gt;
</code></pre>
<h3>Try:</h3>
<pre><code>./prog @ @ @ @ @ @
./prog @ @ @ @ @ @ @ @ @ @ @ @
./prog $(perl -e 'print "@ " x (2*3*5*7);')
./prog $(&lt; Makefile)
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>For this one liner it is best to avoid prime numbers. The output groups
factors in the x-y dimensions. How many factors can be represented before you
run out of command line argument space? How could you modify the program to
experiment with numbers that have more or larger factors?</p>
<h2>Author&rsquo;s comments:</h2>
<p>Visual factorization 1-liner. Try:</p>
<pre><code>gcc -o prog prog.c
./prog @
./prog @ @
./prog @ @ @
./prog @ @ @ @
./prog @ @ @ @ @ @
./prog @ @ @ @ @ @ @ @
./prog @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
</code></pre>
<p>Inspired by <a href="http://www.datapointed.net/visualizations/math/factorization/animated-diagrams/">Animated Factorization Diagrams</a>.</p>
<p>EDIT: <code>prog.orig.c</code> is the original version that I submitted. Gil Dogon kindly improved it during the review. Thank you!</p>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
-121
View File
@@ -1,121 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Most Well-rounded Hash</title>
</head>
<body>
<h1>Most Well-rounded Hash</h1>
<p>Qiming Hou <a href="&#109;&#x61;&#105;&#108;&#116;&#x6f;&#58;&#x68;&#x71;&#109;&#x30;&#x33;&#115;&#116;&#101;&#x72;&#64;&#103;&#x6d;&#97;&#105;&#108;&#x2e;&#99;&#111;&#x6d;">&#104;&#113;&#109;&#x30;&#x33;&#115;&#116;&#x65;&#114;&#64;&#103;&#x6d;&#x61;&#105;&#x6c;&#x2e;&#x63;&#x6f;&#x6d;</a><br>
<a href="http://www.houqiming.net/">http://www.houqiming.net/</a></p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
echo IOCCC | ./prog
</code></pre>
<h3>Try:</h3>
<pre><code>echo "" | ./prog
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>A good start for understanding this entry might be
https://www.ietf.org/rfc/rfc1321.txt. How does it compute this using only a
single looping construct? The original reference source code for this
algorithm is about 355 lines of code, yet this entry is only 199 lines with
one statement per line and it isn&rsquo;t using lots of macro expansion tricks like
the reference code!</p>
<p>Some things that make you go, &ldquo;huh?&rdquo;</p>
<pre><code>./prog &lt; prog.c | cut -c-5
./prog &lt; Makefile | cut -c-4
</code></pre>
<p>How are those values magically returned?</p>
<p>What happens with a large file? Something over 256K</p>
<pre><code>./prog &lt; large_file
</code></pre>
<p>Where does that message come from?</p>
<h2>Author&rsquo;s comments:</h2>
<p>This looks like a normal C program.</p>
<p>Almost everything is a double.</p>
<p>There are tell-tale signs like <code>pow(2,(?/12))</code> and <code>exp(-?*?)</code> (names redacted). You can also find a bunch of cosines and polynomial evaluations.</p>
<p>It looks like a ????? ???????????, right?</p>
<p>Run and find out.</p>
<h3>Why obfuscated</h3>
<p>Some poor scripting folks only have access to doubles (Jav?script, L?a, BA?IC, etc.).</p>
<p>As a C programmer, I feel obliged to show a gesture of sympathy, to experience their pain and provide an answer.</p>
<p>Except when absolutely necessary (<code>printf</code>, <code>int main()</code>, array indexing), there isn&rsquo;t a single integer. Even <code>getchar()</code> and <code>EOF</code> are immediately converted.</p>
<p>Since <code>bool</code> counts as an integer type too, there is no boolean either. No comparison, no <code>if</code>, no <code>?:</code>, no <code>||</code> <code>&amp;&amp;</code>. Everything is done in a single loop that terminates on printf. Straight up arithmetic.</p>
<p><code>floor</code> and <code>ceil</code> are technically double-to-double functions, but they feel like cheating. Yes <code>cos</code>, no <code>floor</code>.</p>
<h3>Limitations</h3>
<p>Hard requirements:</p>
<ul>
<li><p>The platform must implement the <code>double</code> type as IEEE754-compliant 64-bit floating point numbers. The 80-bit intermediate format used by x87 is considered as an violation of this. The code should print an error message on such platforms.</p></li>
<li><p>The program must start with the CPU / FPU in round-to-nearest mode.</p></li>
</ul>
<p>Soft requirements:</p>
<ul>
<li><p>The compiler must respect <code>volatile</code>. The code is formatted to warn about that, though.</p></li>
<li><p>The printed result is only correct on little-endian machines. The program takes care to warn about this issue after printing an incorrect big-endian result. Error messages become garbled, though.</p></li>
</ul>
<p>Tested platforms:</p>
<ul>
<li>Linux 3.18.7, Rasperberry Pi 2, clang 3.0-6.2, (works)</li>
<li>Linux 3.18.7, Rasperberry Pi 2, gcc 4.6.3, (works)</li>
<li>Mac OS X 10, x64, Apple LLVM version 6.1.0 (clang-602.0.53), (works)</li>
<li>Windows 8.1, x86, MSVC 2012 (works)</li>
<li>Windows 8.1, x64, MSVC 2012 (works)</li>
<li>Windows 8.1, x86, MinGW gcc 4.6.2 (fails, prints error message)</li>
<li>Windows 8.1, x86, MinGW gcc 4.6.2 with -msse2 -mfpmath=sse (works)</li>
</ul>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
-155
View File
@@ -1,155 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Most Different</title>
</head>
<body>
<h1>Most Different</h1>
<p>Anthony Howe <a href="&#109;&#x61;&#105;&#108;&#116;&#x6f;&#58;&#x61;&#x63;&#104;&#x6f;&#x77;&#101;&#64;&#115;&#x6e;&#101;&#114;&#x74;&#46;&#99;&#111;&#x6d;">&#97;&#99;&#x68;&#111;&#119;&#101;&#x40;&#x73;&#110;&#101;&#x72;&#116;&#46;&#99;&#x6f;&#x6d;</a><br>
Montreal, Quebec, Canada<br>
<a href="http://www.snert.com/">http://www.snert.com/</a><br>
Twitter: @SirWumpus</p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
./prog file1 file2
./prog -d file1 file2
</code></pre>
<h3>Try:</h3>
<pre><code>./prog prog.orig.c prog.c
make test
./prog -d ABXYEFCD.tmp ACDBECFD.tmp
./prog ABXYEFCD.tmp ACDBECFD.tmp
rm -f curds.tmp whey.tmp
cp /usr/share/man/man1/cc.1 curds.tmp
cp /usr/share/man/man1/cc.1 whey.tmp
chmod 666 whey.tmp
make makeholes
./makeholes -n 1000 whey.tmp
./prog curds.tmp whey.tmp
./avgtime.sh 100 ./prog curds.tmp whey.tmp
# Assuming curl(1) installed, grab a really HUGE text file.
curl -L -o war-and-peace.txt http://www.gutenberg.org/ebooks/2600.txt.utf-8
cp war-and-peace.txt nuked.tmp
./makeholes -c'~' -n 1000 nuked.tmp
./prog war-and-peace.txt nuked.tmp
./avgtime.sh 100 ./prog war-and-peace.txt nuked.tmp
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>This is the best use of the FNV that we have seen in the IOCCC so far!
The output, when used without -d, is compatible with POSIX diff and
is suitable for use with patch.</p>
<p>We welcome back Canada to the list of nations from where winning
entries have been submitted.</p>
<p>Is this code a bug or a feature? :-) Or is this an attempt to corrupt the
programming of our youth? Should we heed Kyle&rsquo;s mom words that she uttered
during a South Park P.T.A. Meeting?</p>
<p> &ldquo;We must stop dirty &copy; language from getting to our children&rsquo;s ears!&rdquo;</p>
<p> <a href="https://www.youtube.com/watch?v=bOR38552MJA">Blame Canada</a>:</p>
<p>Or should we teach our youth to understand the intricacies of this code?
Ying Tong Iddle I Po! We suggest you read the source for yourself, which
might be easier than the academic papers it was inspired by.</p>
<p>NOTE: Unlike the original entry source, prog.orig.c, prog.c uses a
64 bit FNV hash and fixes a function call warning.</p>
<h2>Author&rsquo;s comments:</h2>
<h2>Features</h2>
<ul>
<li><p>&ldquo;An O(NP) Sequence Comparison Algorithm&rdquo; by Wu, Manber, Myers, Miller.</p></li>
<li><p>Output compatible with patch(1).</p></li>
<li><p>Strokes one of the judge&rsquo;s ego (I couldn&rsquo;t email chocolate or curry).</p></li>
</ul>
<h2>Description</h2>
<p>This is a functioning micro diff tool using an <a href="http://myerslab.mpi-cbg.de/wp-content/uploads/2014/06/np_diff.pdf">O(NP) algorithm</a>, compared to the older <a href="http://www.xmailserver.org/diff2.pdf">O(ND) difference algorithm</a> used by some versions of diff. Its output is based on the default diff(1) output described by POSIX and <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/diff.html">The Open Group Base Specifications</a>. The output is suitable for use with patch(1).</p>
<p>The -d option simply writes the edit distance between file1 and file2.</p>
<h2>Observations</h2>
<p>The FNV1a hash is a little slow compared to the trival hash GNU Diff uses. I downloaded a plain text copy of &ldquo;War And Peace&rdquo; from Project Gutenberg, used <code>makeholes.c</code> to make 1000 random changes, then profiled and timed the program verses GNU Diff. The bottle neck appears to be in the file I/O and line hashing with an average +0.05s slower. Using a huge file like &ldquo;War And Peace&rdquo; for testing offsets the diff(1) optimised file I/O.</p>
<p>There is no hash collision checking, partly because FNV1a appears to generate very <a href="http://programmers.stackexchange.com/questions/49550/which-hashing-algorithm-is-best-for-uniqueness-and-speed">few collisions</a> and an assumption that localised collisions within a region of edits are highly unlikely.</p>
<h2>Support Files</h2>
<ul>
<li><p><code>prog-test.sh</code><br>
Basic test program verifies known test edit distances and patch support.</p></li>
<li><p><code>avgtime.sh</code></p></li>
<li><p><code>makeholes.c</code><br>
Random edits (holes) made to a file in-place.</p></li>
</ul>
<h2>References</h2>
<p>Wu, Manber, Myers, and Miller; August 1989;<br>
&ldquo;An O(NP) Sequence Comparison Algorithm&rdquo;;<br>
<a href="http://myerslab.mpi-cbg.de/wp-content/uploads/2014/06/np_diff.pdf">http://myerslab.mpi-cbg.de/wp-content/uploads/2014/06/np_diff.pdf</a></p>
<p>Fowler, Noll, Vo; 1994<br>
<a href="http://www.isthe.com/chongo/tech/comp/fnv/index.html">http://www.isthe.com/chongo/tech/comp/fnv/index.html</a></p>
<p>Fowler, Noll, Vo on Wikipedia<br>
<a href="https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function">https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function</a></p>
<p>&ldquo;diff&rdquo;, The Open Group Base Specifications Issue 7<br>
IEEE Std 1003.1, 2013 Edition<br>
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/diff.html">http://pubs.opengroup.org/onlinepubs/9699919799/utilities/diff.html</a></p>
<p>Eugene W. Myers; &ldquo;An O(ND) Difference Algorithm and Its Variations&rdquo;;<br>
Algorithmica, 1986, pages. 251-266<br>
<a href="http://www.xmailserver.org/diff2.pdf">http://www.xmailserver.org/diff2.pdf</a></p>
<p>Webb Miller and Eugene W. Myers; &ldquo;A File Comparison Program&rdquo;;<br>
Software-Practice And Experience, Vol. 15(11). 1025-1040 (November 1985)<br>
<a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.189.70&amp;rep=rep1&amp;type=pdf">http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.189.70&amp;rep=rep1&amp;type=pdf</a></p>
<p>D.S. Hirschberg, &ldquo;A linear space algorithm for computing maximal common subsequence problem&rdquo;;<br>
Comm. of ACM, Vol. 18, June 1975, pages 341-343<br>
<a href="http://www.mathcs.emory.edu/~cheung/Courses/323/Syllabus/DynProg/Docs/Hirschberg-LCS-1975.pdf">http://www.mathcs.emory.edu/~cheung/Courses/323/Syllabus/DynProg/Docs/Hirschberg-LCS-1975.pdf</a></p>
<p>Which hashing algorithm is best for uniqueness and speed?<br>
<a href="http://programmers.stackexchange.com/questions/49550/which-hashing-algorithm-is-best-for-uniqueness-and-speed">http://programmers.stackexchange.com/questions/49550/which-hashing-algorithm-is-best-for-uniqueness-and-speed</a></p>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
-175
View File
@@ -1,175 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>"For the Birds!" Award</title>
</head>
<body>
<h1>&ldquo;For the Birds!&rdquo; Award</h1>
<p>Chris Mills<br>
Twitter: @MisterXopher</p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
./prog
</code></pre>
<h3>Try:</h3>
<pre><code>Pressing the up arrow and the down arrow at the right time.
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>Did you find that mobile application game a bit frustrating?
Well you can adjust the makefile parameters to make life a
bit easier for you:</p>
<pre><code>make clobber all DW=199999 DW=22 DH=16 DA=50 DI=-150
</code></pre>
<p>From the makefile:</p>
<pre><code># Game parameters
#
DU=99999 # Time between steps in microseconds.
# Make it larger if the game is too fast for you.
DW=28 # Pipe-to-pipe spacing, in columns.
# Farther apart is easier.
DD=20 # Space between pipes.
# The difference between DD and DW is the width of a pipe.
# Narrow pipes are easier to fly though.
DH=8 # Height of gap in pipe.
# Make this larger to make the game easier.
DA=100 # Acceleration due to gravity (scaled by 256).
# Smaller values make you glide slower.
DI=-200 # Impulse velocity of a flap (scaled by 256).
# Make larger if you want an less intense tapping experience!
DB='"&lt;o^="' # Sprite for player when gliding.
# HINT: Try using various emoji.
# NOTE: The string MUST be enclosed inside double quotes.
DF='"&lt;ov="' # Sprite for player when flapping.
# HINT: Try using various emoji.
# NOTE: The string MUST be enclosed inside double quotes.
DG='"Tap to Flap!"' # Instruction text.
# Change to your native tongue.
# NOTE: The string MUST be enclosed inside double quotes.
</code></pre>
<p>Enjoy!</p>
<pre><code>TAP!! TAP!! TAP!!
FLAP! FLAP! FLAP!
</code></pre>
<h2>Author&rsquo;s comments:</h2>
<h1>The Program</h1>
<p>Better late than never to jump on the bandwagon of 2014&rsquo;s most successful
mobile game. The game is called Tappy Bird, and has all the sophisticated
gameplay of the original, except with an exciting twist! (you get to fly to
the right instead of to the left).</p>
<p>In addition, the game features exciting new customization options! Too hard?
Ran into that damn wall too many times? Now you can change physics! Change
any of a number of parameters (speed, gravity, etc.) of the game to suit your
gameplay!</p>
<p>You can even make the game more challenging &ndash; resize the terminal window to
make the world taller or shorter. You&rsquo;ll never be able to get through the
pipes when they are four times as tall!</p>
<h2>Instructions</h2>
<p>The instructions are printed at the start of the game: Tap to Flap!</p>
<p>Hit any key to make your bird fly. Navigate her between the gaps in the pipes.
Your score is shown in the upper left, along with your current high-score.</p>
<h2>Customization options</h2>
<p>To customize the gameplay, change any of the following options on the compile
command line:</p>
<ul>
<li><code>-DU</code>: Time between steps in microseconds. Make it larger if the game
is too fast for you.</li>
<li><code>-DW</code>: Pipe-to-pipe spacing, in columns. Farther apart is easier.</li>
<li><code>-DD</code>: Space between pipes. The difference between <code>D</code> and <code>W</code> is the
width of the pipe. Narrow pipes are easier to fly though.</li>
<li><code>-DH</code>: Height of gap in pipe. Make this larger to reduce the challenge.</li>
<li><code>-DA</code>: Acceleration due to gravity (scaled by 256). Smaller values
make you glide slower.</li>
<li><code>-DI</code>: Impulse velocity of a flap (scaled by 256). Make this smaller
if you want an intense tapping experience!</li>
<li><code>-DB</code>: Sprite for player when gliding.</li>
<li><code>-DF</code>: Sprite for player when flapping.</li>
<li><code>-DG</code>: Instruction text. Change to your native tongue.</li>
</ul>
<p>Feel free to try out physics or playfield options to make the game more
interesting. Try setting the player sprites to change the game completely &ndash;
maybe you can be a fish, or a pig &ndash; the options are limitless! Try using
emoji &ndash; you can be a flying beer mug!</p>
<p>Note that since the <code>curses</code> library on POSIX doesn&rsquo;t natively support wide
characters (needed for UTF-8 support, which is needed for emoji), you may need
to make some changes to the <code>Makefile</code> to get emoji to work on your system.
To help you get started, I&rsquo;ve included some example substitutions for emoji
sprites and instruction text; for example, type</p>
<pre><code>make EMOJI=beer LANGUAGE=spanish
</code></pre>
<p>or</p>
<pre><code>make EMOJI=globe
</code></pre>
<p>for some examples (the full list of options is in the <code>Makefile</code>). Don&rsquo;t
forget to <code>make clean</code> first. If the output doesn&rsquo;t look right, you may need
to link with the &ldquo;wide&rdquo; version of <code>ncurses</code>. On MacOSX 10.11, it should work
with the current <code>-lcurses</code>; on Linux, you probably need <code>-lncursesw</code>.
See the <code>Makefile</code> to make this change if you need to. Or buy a Mac.</p>
<p>You will also need a UTF-8 compatible terminal and an emoji font installed,
and you will need to have your <code>LANG</code> environment variable set to use UTF-8.
Again, if this is too complicated, maybe just go and get that Mac.</p>
<h2>Future additions</h2>
<p>Future versions of the game will include monitization via the freemium model
with micropayments for customization options, play-to-win and of course
live-streamed targeted video advertising.</p>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
-149
View File
@@ -1,149 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Most Compact</title>
</head>
<body>
<h1>Most Compact</h1>
<p>Chris Mills<br>
Twitter: @MisterXopher</p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
./prog compressed_file.Z
</code></pre>
<h3>Try:</h3>
<pre><code>printf '000I\236\f\31H\260\240\301\203' &gt; ioccc.Z
./prog ioccc.Z
dd bs=1k count=4096 &lt; /dev/urandom &gt; test1
compress &lt; test1 &gt; test1.Z
time ./prog test1.Z | cmp - test1
dd bs=1k count=4096 &lt; /dev/zero &gt; test2
compress &lt; test2 &gt; test2.Z
time ./prog test2.Z | cmp - test2
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>Without ASCII art, the source code of this entry would have been exactly 256 bytes.
Compared to <a href="http://ioccc.org/years.html#1990_jaw">1990/jaw</a>, it is very impressive,
even taking into account the missing atob functionality. Now we wish for a compress(1)-like compressor
using a similar idea.</p>
<p>Why is the sad smiley on line 12 in that particular place?</p>
<h2>Author&rsquo;s comments:</h2>
<h1>The Program</h1>
<p>This program is in implementation of the unix <code>zcat(1)</code> command for printing
compressed files that have been created by the <code>compress(1)</code> command.</p>
<p>The adaptive <a href="https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch">LZW</a> compression
employed by <code>compress</code> usually requires a fairly large amount of memory to
build the decompression tables (in fact, <code>compress</code> has a command-line option
to control the size of the decompression tables, since some of the early
systems to which it was ported (<em>cough</em>MS-DOS<em>cough</em>) did not have enough
memory to use the full 16-bit codes). This version has no large static or
dynamic tables. It is able to decompress 16-bit files using a single function
and a few ints.</p>
<p>To run the program, take an existing compressed file and pass it to the program
on the command line. On the odd chance you don&rsquo;t have <code>compress</code> hanging about
on your system, I&rsquo;ve provided compressed copies of this year&rsquo;s IOCCC rules
and guidelines files. To print them, just do</p>
<pre><code>./prog ioccc_guidelines.txt.Z
</code></pre>
<h2>The Details</h2>
<p>The basic cleverness here comes from realizing that the compressed data is
itself an encoded version of the code dictionary. When the encoder sees
an input string that is not in its dictionary, it emits the code corresponding
to the longest prefix that is in the dictionary and adds a new entry consisting
of that code followed by the next input character. This means that when the
decoder wants to know how to decode a code, it just needs to find the spot in
the code-stream where the encoder added that entry to the dictionary. The
code at that spot is the prefix, and the first character of the following code
is the suffix. Decoding then just becomes recursion, to follow the chain of
prefixes and suffix characters.</p>
<p>Of course, it&rsquo;s not nearly that simple. Finding the code in the stream is
complicated by several issues:</p>
<ul>
<li>Codes are at bit offsets within the stream, and must be extracted.</li>
<li>As codes are added to the dictionary, the code word size grows, so finding
the offset to a particular code word is involved.</li>
<li>The <code>compress</code> encoder reserves a code word that clears the coding tables.
When this is encountered, the computation of offsets and bit sizes reset.</li>
<li>The <code>compress</code> decoder is designed to always read a block of eight code
words at the same time, so that it need only read N bytes to get eight N-bit
code words. When the &ldquo;clear&rdquo; code is encountered, the entire eight-word
block is flushed (since the decoder didn&rsquo;t know the word size would change).
The program needs to account for this extra flushing.</li>
<li>The end of the stream is not explicitly marked; the encoder just pads out
the output to the next byte. The decoder must notice this to know when
to stop.</li>
<li>The output stream contains a header that must be skipped.</li>
</ul>
<p>Managing all the details involved added a lovely additional layer of
obfuscation to the otherwise elegant recursive decoder. Still, the code
manages it in a remarkably small amount of code.</p>
<h2>Limitations</h2>
<p>The decoder doesn&rsquo;t look at the header. If you supply something that is not
compressed data, it&rsquo;s likely to crash in an interesting manner.</p>
<p>In particular, it doesn&rsquo;t look at the third byte of the header, which encodes
the maximum code word size and whether &ldquo;block mode&rdquo; was used when the encoder
was run. If you use <code>compress</code> in its default mode, the maximum word size
will be 16 bits and &ldquo;block mode&rdquo; will be enabled. You are unlikely to find
any files that don&rsquo;t use &ldquo;block mode&rdquo;, since all versions of <code>compress</code> after
2.0 (circa 1984) use it by default and have no documented way to disable it.
Reducing the bit depth is still possibly by using the <code>-b</code> flag. Modern
systems have no problem with the 200 KB or so needed for 16-bit decoder
tables, so the need for reducing the table size has passed, hence this program
always assumes 16-bits&hellip; However, should you find a file that needs a
smaller table, feel free to change the hard-coded 16 in the source into the
appropriate number and recompile.</p>
<p>In the event that you don&rsquo;t supply an argument, or that argument doesn&rsquo;t name
a readable file, the program will just silently exit. This is a feature.</p>
<p>The program depends on having a little-endian system. On a big-endian system
you will get a wierd big-endian version of <code>compress</code>, which might have come to
pass in an alternate universe where the vax on which <code>compress</code> was authored
had been big-endian. Luckily for us, it wasn&rsquo;t, and neither are most of the
systems you might want to compile this for.</p>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
-143
View File
@@ -1,143 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Most Complete Use of CPP</title>
</head>
<body>
<h1>Most Complete Use of CPP</h1>
<p>Dominik Muth <a href="&#109;&#x61;&#105;&#108;&#116;&#x6f;&#58;&#x6d;&#x75;&#116;&#x68;&#x2e;&#105;&#111;&#99;&#x63;&#99;&#64;&#x66;&#114;&#101;&#101;&#x6e;&#101;&#116;&#x2e;&#100;&#101;">&#109;&#x75;&#x74;&#104;&#46;&#x69;&#111;&#99;&#99;&#x63;&#x40;&#102;&#x72;&#x65;&#x65;&#x6e;&#x65;&#116;&#46;&#x64;&#101;</a></p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make -B [MACHINE=your_machine.h] [TAPE=your_tape.h] [X=[0|1|2|3|4|5|6|7|8|9]] [V=[0|1|2]] run
</code></pre>
<h3>Try:</h3>
<pre><code>make -B V=2 run
strings prog | grep '(,)'
make -B MACHINE=machine_times2.h TAPE=tape_five.h V=1 run
make -B MACHINE=machine_chaos_5_2.h X=5 run
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>This is something we were fearing all along: that the C preprocessor is Turing-complete
even without conditionals and recursive file inclusion as some kind of a
<a href="https://en.wikipedia.org/wiki/Rewriting">rewriting system</a>. Now we have the proof!</p>
<h2>Author&rsquo;s comments:</h2>
<h3>Preprocessor Turing Engine</h3>
<h4>Features</h4>
<ul>
<li>Turing machine runs in preprocessor</li>
<li>universal (unlimited configurable states, symbols, and tape)</li>
<li>no <code>#if</code>s or other conditional directives, only <code>#define</code>s</li>
<li>no recursive <code>#include</code></li>
<li>single compiler run (no repeated preprocessing)</li>
<li>no variadic macros</li>
<li>verbosity levels:
<ul>
<li><code>V=0</code> (default) only prints the final tape</li>
<li><code>V=1</code> additionally prints one tilde character per machine step (slow)</li>
<li><code>V=2</code> additionally prints details on each machine step (slow; generates large files)</li>
</ul>
</li>
<li>make target <code>run</code> runs <code>./prog</code> and filters a little statistics out of the verbose output</li>
<li><code>X</code> (defaults to 3) sets the maximum number of steps: <em>M</em>(<code>X</code>) ~ 8<sup><code>X</code></sup></li>
</ul>
<h4>Limitations</h4>
<p>If the machine does not halt after <em>M</em>(<code>X</code>) steps, you will see unexpanded macros in the output.</p>
<h4>Compiler warnings</h4>
<p>If <code>V=1</code> or <code>V=2</code> is used, you may see &ldquo;<code>warning: string length is greater than the length '4095' ISO C99 compilers are required to support</code>&rdquo;.</p>
<h4>Programming</h4>
<p>Implementing your own Turing machine is easy. Take a look at the supplied header files for examples.</p>
<h5>Tape Symbols</h5>
<p>Every symbol used (except &ldquo;<code>_</code>&rdquo;) must be explicitly declared using</p>
<pre><code>#define sym_SYMBOL(sym, _SYMBOL) sym
</code></pre>
<p>Example:</p>
<pre><code>#define sym_1(sym, _1) sym
</code></pre>
<h5>Tape</h5>
<p>The initial content of the tape must be defined in the tape header using a triple like:</p>
<pre><code>#define tape ((((,),...l2), l1), c, (r1, (r2..., (,))))
</code></pre>
<ul>
<li><code>l1</code>, <code>l2</code>, &hellip; are the symbols to the left</li>
<li><code>c</code> is the symbol at the current position</li>
<li><code>r1</code>, <code>r2</code>, &hellip; are the symbols to the right</li>
</ul>
<p>The empty pairs &ldquo;<code>(,)</code>&rdquo; represent the continuations of the tape, filled with underscore symbols (&ldquo;<code>_</code>&rdquo;). They are expanded on demand.</p>
<h5>State Machine</h5>
<p>All transitions are defined in the machine header using the syntax</p>
<pre><code>#define CURRENT_SCANNED (WRITE, MOVEMENT, NEXT)
</code></pre>
<p>where</p>
<ul>
<li><code>CURRENT</code> is the current state</li>
<li><code>SCANNED</code> is the symbol at the current position</li>
<li>the whitespace before the parentheses is significant</li>
<li><code>WRITE</code> is the symbol to be written to the tape</li>
<li><code>MOVEMENT</code> is &ldquo;<code>L</code>&rdquo; for left, &ldquo;<code>R</code>&rdquo; for right, or nothing</li>
<li><code>NEXT</code> is the next state</li>
</ul>
<p>There must be a state &ldquo;<code>A</code>&rdquo; defined, which becomes the initial state of the machine.</p>
<p>To halt the machine, use the keyword &ldquo;<code>break</code>&rdquo; as in</p>
<pre><code>#define A_1 (2, break)
</code></pre>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
-805
View File
@@ -1,805 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Best Documented</title>
</head>
<body>
<h1>Best Documented</h1>
<p>Jens Schweikhardt<br>
<a href="http://www.schweikhardt.net">http://www.schweikhardt.net</a></p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
./prog n
where n is a base 16 number of any size
</code></pre>
<h3>Try:</h3>
<pre><code>./prog 19
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>This code is clean. When you compile with all warnings enabled,
such as with clang:</p>
<p> cc -Weverything -pedantic -std=c11 -Dtyp=uint64_t -O3 prog.c -o prog</p>
<p>The code compiles without warnings on the systems that we tested!</p>
<p>Even more, the code was 100% clean when we ran it against various
static source checkers.</p>
<p>This tool references a problem that David I. Bell once described
as having one of the largest &ldquo;yummo quotients&rdquo; in number theory:</p>
<pre><code> complexity of the solution
yummo quotient = -----------------------------------
complexity of the problem statement
</code></pre>
<p>Erdős privately told one of the IOCCC judges:</p>
<p>&ldquo;Solving the <a href="https://en.wikipedia.org/wiki/Generalized_Riemann_hypothesis#Extended_Riemann_hypothesis_.28ERH.29">Generalized Riemann hypothesis</a>
would be a good warmup exercise for someone to get ready
to begin to work on the <a href="https://en.wikipedia.org/wiki/Collatz_conjecture">Collatz conjecture</a>.&rdquo;</p>
<p>You may explore this famous conjecture using this entry:</p>
<pre><code>./prog 2410
./prog abfff
./prog 27f8cebf
./prog 246f8fddf
./prog 2e95ab51ffea9de
./prog e6a5c22fd7bde9f
./prog 1b7dd73a937485bf
./prog 7d3237680d190a77e53751b
./prog 302ab3d052fb87c06228d249581be0e4
</code></pre>
<p>When you first look at the source, the code looks fairly straightforward.
But look again. Like the Collatz conjecture, simplicity is deceptive!
Oh, and the variable names? They are not simple single letter variables,
they are names of various <a href="https://en.wikipedia.org/wiki/Proteinogenic_amino_acid">Proteinogenic amino
acid</a>:
which is yet another simple building block that can be used to
build some very complex structures. :-)</p>
<p>p.s. We appreciated that apart from a few powers of 2, the source
code is magic number free.</p>
<h2>Author&rsquo;s comments:</h2>
<h2>The TL;DR version</h2>
<p>This is the cleanest program ever submitted. If for some input it enters
a non-terminating loop or runs out of memory you will be insta-famous.
It&rsquo;s a bit like a lottery without the need to buy a ticket and you can
play as often as you like. One notable historic person has even offered
some prize money.</p>
<p>The program illustrates the bloat caused by adherence to too many rules,
each of which may sound sane in isolation, but in their entirety lead to
an obfuscated, hard to read and understand monster.</p>
<h2>What this program does.</h2>
<p>The program tests whether a given natural number satisfies the
<a href="https://en.wikipedia.org/wiki/Collatz_conjecture">Collatz Conjecture</a>:</p>
<p>Take any natural number <em>n</em>. If <em>n</em> is even, divide it by 2 to get <em>n</em>/2.
If <em>n</em> is odd, multiply it by 3 and add 1 to obtain 3<em>n</em> + 1.
Repeat the process indefinitely.
The conjecture is that no matter what number you start with,
you eventually reach 1.</p>
<p>Paul Erdős said about the Collatz conjecture:
&ldquo;Mathematics may not be ready for such problems.&rdquo;
He also offered $500 for its solution.</p>
<p>For example, the sequence of numbers for <em>n</em> = 6 is</p>
<blockquote><p> 6, 3, 10, 5, 16, 8, 4, 2, 1.</p></blockquote>
<p>Continuing past one leads to the <em>cycle</em> 1, 4, 2, 1, 4, 2, 1, &hellip;
Interesting factoid: if you allow <em>negative</em> start values, there are
a few more cycles, each of different length:</p>
<blockquote><p> −1, −2, −1</p>
<p> −5, −14, −7, −20, −10, −5</p>
<p> −17, −50, −25, −74, −37, −110, −55, −164, −82, −41, −122, −61, −182, −91, −272, −136, −68, −34, −17</p></blockquote>
<p>The program computes the sequence for a given positive natural number
and stops at 1. The number <em>n</em> is specified in hexadecimal (without 0x
prefix) as the first argument. The program prints the given number in
zero-padded hex and each iteration along with a line count in decimal.
The example above looks like this (compiled with 64 bit word size):</p>
<pre><code>$ ./prog 6
0000000000000006
0000000000000003 1
000000000000000A 2
0000000000000005 3
0000000000000010 4
0000000000000008 5
0000000000000004 6
0000000000000002 7
0000000000000001 8
</code></pre>
<p>The size of <em>n</em> is only limited by the argument size limit of your
shell/OS (the program implements arbitrary size bignums).
To query this on your POSIX system, run</p>
<pre><code>$ getconf ARG_MAX
262144
</code></pre>
<p>which reports the limit in bytes, here 256KB. This allows to test
whether a <a href="https://en.wikipedia.org/wiki/Googol">Googol</a>, which is
10<sup>100</sup>, satisfies the conjecture. But what is a googol in hex?
Fear not,
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html">bc(1)</a>
to the rescue:</p>
<pre><code>$ printf 'obase=16;10^100\n' | bc
1249AD2594C37CEB0B2784C4CE0BF38ACE408E211A7CAAB24308A82E8F1000000000\
0000000000000000
$ ./prog 1249AD2594C37CEB0B2784C4CE0BF38ACE408E211A7CAAB24308A82E8F10000000000000000000000000 \
| less
[...]
</code></pre>
<p>Observe how the first 100 iterations melt the zeros to the right. Can you explain
why?</p>
<p>For a given <em>n</em> the program behavior is one of the following 3:</p>
<ol>
<li>The sequence stops at 1. No fame. No money. Thanks for playing. Computational
mathematicians have tested all <em>n</em> &lt; 4FFDD776055A0000 (~10<sup>18</sup>)
so don&rsquo;t try anything less than that.</li>
<li>The chosen <em>n</em> leads to a sequence with ever bigger numbers,
so that eventually the bignum cannot be stored in memory. If this happens,
the program outputs <code>laugh</code> (more likely) or <code>throw up</code> (less likely) and
stops. You <em>might</em> have found
a number for which the sequence <em>diverges</em>. If confirmed, this disproves the
conjecture.</li>
<li>The chosen <em>n</em> leads to a cycle not including 1 (i.e. runs forever,
repeating the same sequence over and over). You have disproved the
conjecture and should certainly submit a paper to the nearest
mathematical journal.</li>
</ol>
<h2>Design objectives</h2>
<p>I gave myself the following objectives. Like in real world programming,
not all of them can be met 100%. Think of them as a multidimensional
continuum, where trade-offs have to be made.</p>
<ol>
<li>No arbitrary limits on the input number. 64 bits might be enough
for everybody, but is not enough for exploring new Collatz-territory.
Thus bignums are required.</li>
<li>Ultra-portable. Must run on C89 systems and self-adapt to C99 and C11
features like exact width types.</li>
<li>Super-efficient. Must be able to run with the widest type as the
base of the bignums. Make the user select the widest type supported
by the implementation and then crunch away. If a non-standard
128bit type is available, it should be usable.</li>
<li>Pentagon level lint cleanliness and MISRA compliance.</li>
<li>Easy to understand, self-documenting clear code. A joy for maintenance
programmers. The epitome of best practice demonstration for all
future textbooks on C.</li>
</ol>
<h1>Program Obfuscation</h1>
<p>In the following I address all the <em>tests</em> as specified by your honors in the
<em>guidelines</em>.</p>
<ul>
<li>look at the original source</li>
<li>convert ANSI tri-graphs to ASCII</li>
<li>C pre-process the source ignoring <code>#include</code> lines</li>
<li>C pre-process the source ignoring <code>#define</code> and <code>#include</code> lines</li>
<li>run it through a C beautifier</li>
<li>examine the algorithm</li>
<li>compile it (with flags to enable all warnings)</li>
<li>execute it</li>
</ul>
<h2>Look at the original source</h2>
<p>Using one letter identifiers is quite old. I decided to use TLI (three
letter identifiers). Not the random kind, rather with a connection to
the meaning of life, the universe and the rest. Enter amino acids! Among
the myriad of possible amino acids there are 23 from which proteins are
built. In biochemistry, each is assigned a TLI (see <a href="https://en.wikipedia.org/wiki/Proteinogenic_amino_acid">Proteinogenic amino
acid</a>):</p>
<pre><code>ala Alanine
cys Cysteine
asp Aspartic acid
glu Glutamic acid
phe Phenylalanine
gly Glycine
his Histidine
ile Isoleucine
lys Lysine
leu Leucine
met Methionine
asn Asparagine
pyl Pyrrolysine
pro Proline
gln Glutamine
arg Arginine
ser Serine
thr Threonine
sec Selenocysteine
val Valine
trp Tryptophan
tyr Tyrosine
asx Asparagine or Aspartic acid
glx Glutamic acid or Glutamine
xle Leucine or Isoleucine
unk Unknown
</code></pre>
<p>My own research results complete this list (not yet in Wikipedia due to
the rule &ldquo;<a href="https://en.wikipedia.org/wiki/Wikipedia:No_original_research">No original
research</a>&rdquo;):</p>
<pre><code>and Androgynine
xor Xenoricine
not Notanamine
tla Triletramine
</code></pre>
<p>Interestingly, the TLI are the perfect mnemonics for C language source.
For example, <code>met</code> is &ldquo;Main&rsquo;s Exit Type&rdquo; (<code>int</code>), <code>ala</code> is &ldquo;A Large
Algebraic&rdquo; (bignum), <code>ile</code> an &ldquo;Incremented Local Entity&rdquo; (index
counter), <code>gly</code> means &ldquo;Grow Larger memorY&rdquo;, <code>gln</code> is &ldquo;Grown Larger Now&rdquo;
(after realloc), <code>not</code> is a &ldquo;Not Overflowing Type&rdquo; (recursive!), <code>unk</code>
is the &ldquo;UNit (Known as 1)&rdquo;, <code>trp</code> is the &ldquo;Tabula Rasa Product&rdquo; (zero),
<code>phe</code> is &ldquo;Print HEx&rdquo; and so on.</p>
<h2>Convert ANSI tri-graphs to ASCII</h2>
<p>Huh??!</p>
<h2>C pre-process the source ignoring &lsquo;#include&rsquo; lines</h2>
<p>Wow, an identity operation (except for the <code>&lt;stdint.h&gt;</code> and <code>EOF + __STDC__</code>
trivialities). Did you gain any insight through this?</p>
<h2>C pre-process the source ignoring &lsquo;#define&rsquo; and &lsquo;#include&rsquo; lines</h2>
<p><code>#define</code>? Which <code>#define</code> directives? How many 4K source files do you
see that neither use a single <code>#define</code> directive <em>nor</em> abuse the build
file? Even though the &ldquo;no <code>#define</code>&rdquo; rule I submitted myself to made it
hard, I could use <code>__LINE__</code> and stdio macros <code>EOF</code>, <code>L_tmpnam</code>,
<code>BUFSIZ</code>, <code>FILENAME_MAX</code>, <code>TMP_MAX</code> to obfuscate at least something.</p>
<h2>Run it through a C beautifier</h2>
<p>Another identity operation. I&rsquo;ve done it for you already. Use this
<code>.indent.pro</code> with FreeBSD indent:</p>
<pre><code>$ cat .indent.pro
-bad /* blank line after decls */
-bap /* blank line after functions */
-br /* braces on if line */
-i8 /* indent */
-l999 /* line length */
-npcs /* no space after function call names */
-npsl /* don't break procedure type */
-ut /* use tabs */
-ce /* cuddle else */
-nip /* no parameter indentation */
-di1 /* declaration indent */
-Tand
-Tmet
-Tthr
-Tpro
-Tser
-Tala
</code></pre>
<p>It looks like a perfect program should:</p>
<ul>
<li> two and a half <code>#includes</code> of unsuspicious standard headers</li>
<li> followed by self protection against goofy implementations</li>
<li> followed by a handful of <code>typedef</code>s</li>
<li> and a pair of file scope objects by necessity</li>
<li> prototypes! With parameter names! <code>static</code> for internal linkage even! This <strong>must</strong> be a first in IOCCC history.</li>
<li> function definitions, <code>main</code> last</li>
<li> everything is fully const-poisoned: automatics, statics, arguments, even <code>main</code></li>
<li> everything is fully curly braced, even single statements</li>
<li> plenty of meaningful TLC (Three Letter Comments)</li>
</ul>
<p>The program contains not a single <em>magic number</em> (only 0 and powers of
2, each power from 1 to 512) which are obvious to competent software
engineers). How many programs have <em>that</em> property? The check for
<code>__STDC_VERSION__</code> was a bit tough to arrive at, since 199901L has too
many bits set. But I realized that I only needed a number larger than
199409 and less than 199901. 199680 has only 4 bits set and writing it
as (256 + 128 + 4 + 2) * 512 minimizes the character count. That&rsquo;s what
judges get when they don&rsquo;t like programs that are longer than they need
to be.</p>
<h2>Examine the algorithm</h2>
<p>Spoilers ahead. Duh!</p>
<p>Pseudocode, with comments matching those in the C source:</p>
<pre><code>/* run */
if (non-NULL and nonempty argv[1]) {
n = convert(argv[1])
print n /* 2hx */
while (n != 1) { /* one */
if (n is odd) { /* odd */
m = deep copy of n /* cpy */
n &lt;&lt;= 1 /* shl */
n += m /* add */
increment n /* inc */
} else { /* eve */
n &gt;&gt;= 1 /* shr */
}
print n /* 2hx */
}
}
</code></pre>
<p>Bignums are represented as the two member structs</p>
<pre><code>typedef struct {
size_t places; /* number of places in base 2&lt;sup&gt;8*sizeof(type)&lt;/sup&gt; */
type *number; /* dynamically allocated memory for number */
} bignum
</code></pre>
<h2>Compile it (with flags to enable all warnings)</h2>
<p>Here&rsquo;s where the program shines brighter than a <a href="https://en.wikipedia.org/wiki/Gamma-ray_burst">gamma-ray
burst</a>!</p>
<p>I challenge you to throw all kinds of compilers, lints, checkers and
analyzers at my program and make it find the slightest of issues.</p>
<p>Is <code>clang -Wall -Wextra -Weverything -Dtyp=uint32_t prog.c</code> all you can
do? Clang has implemented a new warning? Bring it on!</p>
<h2>Execute it</h2>
<p>May you win the jackpot!</p>
<p>For least surprising results, the execution character set should be
ASCII. The program computes four bits from every character in <code>argv[1]</code> and
interprets them as a hex digit. On ASCII the characters a-f, A-F and 0-9
are converted as expected.</p>
<p>This means however, that the program accepts <strong>any string</strong>, turns it
into a starting number (which is output as the first line), and starts
crunching. Nothing stops you from executing</p>
<pre><code>$ ./prog "$(cat prog.c)" # Kind of quine?
$ ./prog "$(cat rules guidelines)" # A jackpot? Maybe next year...
$ ./prog "$(cat /bin/ls)" # Number cut short at first NUL byte.
</code></pre>
<p>In a certain way, the program is character set and encoding agnostic.</p>
<h2>Assumptions made</h2>
<ul>
<li>The <code>EOF</code> macro from <code>&lt;stdio.h&gt;</code> must expand to negative one since it is used
to decrement a pointer and do some other math.
None of the tools catches this one. The program self-protects against unusual
systems with <code>#if EOF + __STDC__</code> followed by <code>#error goofy!</code>. In the rare event
your system is goofy, replace all <code>EOF</code> tokens with <code>(-1)</code> and remove the
<code>#error</code> directive.</li>
</ul>
<p>While the program works best when bytes/characters are octets and the
number of bits in a type is <code>sizeof(typ) &lt;&lt; 3</code>, it will work correctly
on 24bit or 36bit systems with 9 bits/byte, or systems where
<code>sizeof(typ)</code> is 1 even for <code>int</code> and so on. On such systems, it will only
use 8 * <code>sizeof(typ)</code> bits per place. It does not work when <code>CHAR_BIT &lt;= 7</code>.</p>
<h2>Results of various checkers</h2>
<h3>cppcheck</h3>
<p>The open source static checker <a href="http://cppcheck.sourceforge.net/">cppcheck</a>
checks various problems with respect to style, performance, portability
and general fishiness. To enable all checks, run</p>
<pre><code>$ cppcheck --enable=all --force -I/usr/include -Dtyp=uint32_t prog.c
</code></pre>
<p>No issues found.</p>
<h3>flawfinder</h3>
<p>The open source static checker <a href="http://www.dwheeler.com/flawfinder/">flawfinder</a>
checks various problems with respect to security like buffer overflows,
function arguments to known troublemaker functions and more. It doesn&rsquo;t need to
pre-process code, so can be run without the <code>typ</code> macro being defined:</p>
<pre><code>$ flawfinder prog.c
Flawfinder version 1.31, (C) 2001-2014 David A. Wheeler.
Number of rules (primarily dangerous function names) in C/C++ ruleset: 169
Examining prog.c
FINAL RESULTS:
ANALYSIS SUMMARY:
No hits found.
$
</code></pre>
<h3>valgrind</h3>
<p>The open source dynamic checker <a href="http://valgrind.org/">valgrind</a>
runs an executable and verifies all memory accesses and (de)allocations for
proper bounds and memory leaks.
Since the program frees all memory in all possible execution paths, even when
it must bail out,
valgrind should be happy. An early version of my program however reported this:</p>
<pre><code>$ valgrind --leak-check=full --show-leak-kinds=all ./prog 6
[...]
==14615== HEAP SUMMARY:
==14615== in use at exit: 4,096 bytes in 1 blocks
==14615== total heap usage: 4 allocs, 3 frees, 4,108 bytes allocated
==14615==
==14615== 4,096 bytes in 1 blocks are still reachable in loss record 1 of 1
==14615== at 0x4C236C0: malloc (in /usr/local/lib/valgrind/vgpreload_memcheck-amd64-freebsd.so)
==14615== by 0x4F62175: ??? (in /lib/libc.so.7)
==14615== by 0x4F62073: ??? (in /lib/libc.so.7)
==14615== by 0x4F514EE: ??? (in /lib/libc.so.7)
==14615== by 0x4F51265: vfprintf_l (in /lib/libc.so.7)
==14615== by 0x4F3E001: printf (in /lib/libc.so.7)
==14615== by 0x40101E: phe (in ./prog)
==14615== by 0x400A9F: main (in ./prog)
==14615==
==14615== LEAK SUMMARY:
==14615== definitely lost: 0 bytes in 0 blocks
==14615== indirectly lost: 0 bytes in 0 blocks
==14615== possibly lost: 0 bytes in 0 blocks
==14615== still reachable: 4,096 bytes in 1 blocks
==14615== suppressed: 0 bytes in 0 blocks
==14615==
==14615== For counts of detected and suppressed errors, rerun with: -v
==14615== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
</code></pre>
<p>From which I concluded that <code>printf</code> allocated a single 4K block for
which no matching free existed. But how to free memory allocated deep
down in the guts of the Standard I/O library? After some serious head
scratching it hit me. The only chance I have is telling the system I no
longer want to do I/O, maybe then it would free that buffer. A reading
of C99 7.19.5.1, &ldquo;The fclose function&rdquo;, was encouraging:</p>
<blockquote><p> Whether or not the call succeeds, the stream is disassociated from the file
and any buffer set by the <code>setbuf</code> or <code>setvbuf</code> function is disassociated from the stream
(and deallocated if it was automatically allocated).</p></blockquote>
<p>So I <code>fclose(stdout)</code> before returning and now:</p>
<pre><code>$ valgrind --leak-check=full --show-leak-kinds=all ./prog 6
==14571== Memcheck, a memory error detector
==14571== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==14571== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==14571== Command: ./prog 6
==14571==
0000000000000006
0000000000000003 1
000000000000000A 2
0000000000000005 3
0000000000000010 4
0000000000000008 5
0000000000000004 6
0000000000000002 7
0000000000000001 8
==14571==
==14571== HEAP SUMMARY:
==14571== in use at exit: 0 bytes in 0 blocks
==14571== total heap usage: 4 allocs, 4 frees, 4,120 bytes allocated
==14571==
==14571== All heap blocks were freed -- no leaks are possible
==14571==
==14571== For counts of detected and suppressed errors, rerun with: -v
==14571== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
</code></pre>
<p>A squeaky clean valgrind result!</p>
<h3>FlexeLint</h3>
<p>FlexeLint is a commercial lint tool by <a href="http://www.gimpel.com/html/index.htm">Gimpel
Software</a>. It supports nearly a
thousand checks, broadly categorized into 4 levels,</p>
<ol>
<li> Syntax errors only (messages 1 to 399)</li>
<li> Warnings (messages 400 to 699)</li>
<li> Informational messages (700 to 899)</li>
<li> Elective notes (900 to 1000 and > 9000)</li>
</ol>
<p>There is an <a href="http://www.gimpel-online.com/OnlineTesting.html">on-line
demonstrator</a> you can
use for checking your C programs and I highly recommend trying it. For a start,
paste the well know first program in the form and press &ldquo;Analyze Code&rdquo;. Note
the FlexeLint configuration options in comments (no space between <code>/*</code> and <code>lint</code>).</p>
<pre><code>/*lint -w4 turn on everything */
/*lint +esym(534,*) no demonstrator defaults */
/*lint -e966 indirectly included header file not used */
/*lint -esym(9058,_*) tag not used outside typedef */
/*lint -misra(2) */
#include &lt;stdio.h&gt;
int main(void)
{
printf("hello, world\n");
return 0;
}
</code></pre>
<p>Possible checks include those for MISRA 2004 compliance verification.
The <a href="https://en.wikipedia.org/wiki/Motor_Industry_Software_Reliability_Association">Motor Industry Software Reliability
Association</a>
has produced a <a href="http://doc.hcc-embedded.com/display/CODING/MISRA+Rules">list of 121 required and 20 advisory
rules</a> for C
programming. I am proud to report that my program fulfills <em>almost all</em>
rules. To assess the few exceptions, one has to understand that MISRA
rules are geared towards embedded systems used in the automotive
industry. That&rsquo;s why features like <code>malloc</code> and <code>printf</code> are right out.
But that&rsquo;s too restrictive for an IOCCC hosted application, so I ignored
these:</p>
<ul>
<li>17.1 Pointer arithmetic shall only be applied to pointers that address an array or array element.</li>
<li>17.4 Array indexing shall be the only allowed form of pointer arithmetic.</li>
<li>20.4 Dynamic heap memory allocation shall not be used.</li>
<li>20.9 The input/output library stdio.h shall not be used in production code.</li>
<li>20.11 The functions abort, exit, getenv, and system from the library stdlib.h shall not be used.</li>
</ul>
<p>I started out with enabling <em>all</em> messages using FlexeLint&rsquo;s <code>-w4</code>
option and disabling all noise from system headers. Then I dealt with
the remaining messages by addressing them or suppressing them in such a way
that the set of suppressions was minimal. At the end of the day, this is
what remained:</p>
<pre><code>// === Tested with FlexeLint 9.00L on FreeBSD 11 ===
// Compiler:
// "4.2.1 Compatible FreeBSD Clang 3.6.1 (tags/RELEASE_361/final 237755)"
-w4 // Enable maximum pickiness
-passes(6) // Recommended in FlexeLint manual for torture testing
+fsc // Make string literals have type const char*
+fnr // ptr-returning functions may return NULL
-strong(AJX,and,pro,ser,ala) // strong types
-strong(AcJcm,thr) // thr is strong, but most arithmetic is okay
-strong(AarJemorX,met) // met is strong, but some use is okay
+libclass(angle) // All &lt;headers&gt; are system headers
-wlib(1) // Only errors for system headers
-i/usr/include // System headers
-i/usr/local/lib/supp/ansi // Comes with FlexeLint
-d__GNUC__=4 // Pretend...
-d__GNUC_MINOR__=2 // I'm...
-d__GNUC_PATCHLEVEL__=1 // someone else.
-d__builtin_va_list=char* // Fake this compiler extension
-d__inline= // Delete this compiler extension
-d__attribute__(x)= // Delete this compiler extension
+e900 // Announce number of messages produced
// MISRA 2004 checking
/usr/local/lib/supp/lnt/au-misra2.lnt // Enable all MISRA checking
-elib(960) // Don't check FreeBSD system headers for required rules
-elib(961) // Don't check FreeBSD system headers for advisory rules
-e829 // stdio.h used
-e522 // MISRA 14.2 Highest operation, lacks side-effects
-esym(960,17.4) // pointer arithmetic other than array indexing used
-e971 // char without signed/unsigned
-e974 // stack usage report
// Use verboten functions, Req. Rules 20.4 malloc() et al., 20.11, exit()
-esym(586,malloc,realloc,calloc,free,exit)
-e911 // implicit promotion of smaller than int to int
-e921 // cast from integral to integral
-e925 // cast from pointer to pointer
-e958 // padding required in struct
+e9??? // Enable all 9xxx informational messages, except:
-e9079 // conversion from pointer to void to pointer to other type
-e9087 // cast performed between a pointer to object type and a
// pointer to a different object type
-e9141 // global declaration of symbol
// Messages due to code in FreeBSD headers.
//
-dlint // The "lint" macro is tested in x86/_types.h
-elib(537) // Repeated include file
-e793 // external identifiers &gt; 6 chars
-e935 // (unsigned) int within struct (actually the size_t)
-estring(960,_*) // Could be defined at block scope
-e964 // Header file not directly used
-e966 // Indirectly included header file not used
-elib(970) // int outside typedef
-esym(9003,_*) // could be defined at block scope
-elib(9047) // FILE pointer dereferenced
-esym(9058,__*) // tag not used outside typedef
-e9092 // NULL does not expand to a pointer (but plain 0)
</code></pre>
<h2>Compulsory obfuscations</h2>
<p>Which of the rules cause which obfuscation?</p>
<p>MISRA 6.1, &ldquo;The plain char type shall be used only for the storage and
use of character values.&rdquo; This forbids using character constants in
expressions other than assignments to <code>char</code> objects. A consequence is
that printing digits with <code>'0' + digit</code> is not allowed (even though
<code>'0'</code> is technically an <code>int</code>!) so I am forced to output hex digits with</p>
<pre><code>printf("%c", (met)tyr + 32 + 16 + ((8 + EOF) * ((met)tyr / (8 + 2))));
</code></pre>
<p>because of the &ldquo;no magic numbers other than powers of two&rdquo; rule. How is this
an improvement over <code>printf("%c", '0' + tyr + 7 * (tyr / 10)</code>, MISRA?</p>
<p>MISRA 6.3 &ldquo;typedefs that indicate size and signedness should be used in
place of the basic types.&rdquo; Well, if you can&rsquo;t infer the size and
signedness from <code>typedef int met</code>, you&rsquo;re not a real C programmer.</p>
<p>MISRA 10.5, &ldquo;If the bitwise operators <code>~</code> and <code>&lt;&lt;</code> are applied to an
operand of underlying type <code>unsigned char</code> or <code>unsigned short</code>, the
result shall be immediately cast to the underlying type of the operand.&rdquo;
Because the program must work for any unsigned type chosen for the <code>typ</code>
macro, including the narrow types enumerated in the rule, a lot of
redundant casting ensues. It gets worse with the next rule&hellip;</p>
<p>MISRA 12.1, &ldquo;Limited dependence should be placed on the C operator
precedence rules in expressions.&rdquo; This requires parentheses for almost
all expressions involving more than one operator, especially those for which
a cast is required, leading to hard to understand expressions such as</p>
<pre><code>const ser glx = (ser)((asx &gt; (ser)64u) ? (ser)((ser)asx + (ser)8u + (ser)1u) : (ser)asx);
not.not[leu] = (and)((and)not.not[leu] | (and)(((and)glx % (and)16u) &lt;&lt; (and)lys));
</code></pre>
<p>MISRA 14.7, &ldquo;A function shall have a single point of exit at the end of
the function.&rdquo; Sigh. Since I must use eloquent prototypes (8.1, 16.3,
16.4) and static functions (8.10, 8.11), I can only use a few functions.
Everything usually written with an early <code>return</code> now cause <em>another
useless indent level</em>. The first three <code>if</code> statements in <code>main</code> cause a
silly 24 character indent. The maximum indent is forced to 8, which is way
too high for a sane function.</p>
<p>MISRA 16.10, &ldquo;If a function returns error information, then that error
information shall be tested.&rdquo; A cast to void would draw a lint warning, so
I use the <code>printf</code> result in expressions,</p>
<pre><code>lys -= 4 * printf("%c", (met)tyr + 32 + 16 + ((8 + EOF) * ((met)tyr / (8 + 2))));
val += printf("\n") / ((__LINE__ * L_tmpnam) + TMP_MAX);
val -= (printf(" %d\n", val) &gt; BUFSIZ) ? FILENAME_MAX : EOF;
</code></pre>
<p>which are, in the absence of errors, equivalent to</p>
<pre><code>lys -= 4;
/*nop*/
++val;
</code></pre>
<p>MISRA 13.1, &ldquo;Assignment operators shall not be used in expressions that
yield a Boolean value.&rdquo; Forbids the idiomatic <code>if ((p = malloc(n)) ==
NULL)</code> and requires separate statements, in other words, bloat.</p>
<p>MISRA 16.7, &ldquo;A pointer parameter in a function prototype should be
declared as pointer to const if the pointer is not used to modify the
addressed object.&rdquo; in conjunction with lint&rsquo;s &ldquo;Note 952: Parameter could
be declared const&rdquo; causes const-poisoning for all functions,</p>
<pre><code>static void phe(const ala not);
static void gly(ala *const not, const and his);
met main(met val, const pro *const his[]);
</code></pre>
<p>and quite a number of automatic variables.</p>
<h3>Why the &ldquo;laugh&rdquo; and &ldquo;throw up&rdquo; messages?</h3>
<p>The guidelines state &ldquo;We like programs that: make us laugh and/or throw
up :-) (humor really helps!)&rdquo;</p>
<h3>If you have a 128 bit type</h3>
<p>If your compiler supports a 128 bit wide type (e.g. clang, gcc) then
you can use it via the <code>typ</code> macro:</p>
<pre><code>clang -Dtyp=__uint128_t -o prog prog.c
</code></pre>
<p>Indeed, the program can use (and lints clean for) all of</p>
<pre><code>clang -Dtyp=uint8_t -o prog8 prog.c
clang -Dtyp=uint16_t -o prog16 prog.c
clang -Dtyp=uint32_t -o prog32 prog.c
clang -Dtyp=uint64_t -o prog64 prog.c
clang -std=c89 -Dtyp="unsigned long" -o prog89 prog.c
</code></pre>
<p>This works because the program has no need for corresponding <code>SCN</code> or
<code>PRI</code> macros to do the scanning and printing of variables of these
types. With a 128 bit type the program can represent numbers up to
340282366920938463463374607431768211457 (3.4 * 10<sup>39</sup>) as a
single &ldquo;place&rdquo;, enough to explore yet untested numbers for the rest of
your life.</p>
<h3>How big a number can I test with 4 GB of RAM?</h3>
<p>The number of hex digits in the start number is limited by <code>ARG_MAX</code>,
probably minus some overhead for the environment variables (use
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/env.html"><code>env</code>(1)</a>
to trim your environment). In bits this leaves you with 2<sup>4 *
ARG_MAX</sup>.</p>
<p>The algorithm requires two bignums in memory for addition.
If you hit a divergent number, this will cause out-of-memory (&ldquo;laugh&rdquo;)
somewhere near 2<sup>16,000,000,000</sup> (4GB/2 * 8bits/byte).
Sadly, I don&rsquo;t have a test case :-)</p>
<p>How long would it take to overflow the <em>Not Overflowing Type</em>? Lets
assume we&rsquo;re processing 2GB numbers. The program copies, shifts by one,
adds and increments 2GB long bit strings, each time completely thrashing
the data cache &ndash; at <em>all</em> levels. We have a fast machine that can do an
iteration in one second, on average. To make things easy, we round up
3<em>n</em> + 1 to 4<em>n</em>, and assume we never need to divide by two (which is
quite optimistic). Then each iteration shifts left by 2. This would take
8 billion seconds, or about 250 years. If you want to get famous, you
better <em>remove</em> some of the RAM, use an ancient box, or reduce available
memory resources with the ulimit(1) built-in of your shell.</p>
<p>For all intents and purposes, the <em>Not Overflowing Type</em> keeps the promise!</p>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
-144
View File
@@ -1,144 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.1.5a DL=DISCOUNT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Most Pointed Reaction</title>
</head>
<body>
<h1>Most Pointed Reaction</h1>
<p>Don Yang<br>
<a href="http://uguu.org/">http://uguu.org/</a></p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
echo Some text | ./prog
</code></pre>
<h3>Try:</h3>
<pre><code>echo IOCCC 2015 | ./prog | tee output.c
make output
./output
echo IOCCC 2015 | ./prog_c11 | tee output.c
make output
./output
echo IOCCC 2015 | ./prog_c++98 | tee output.c
make output
./output
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>Before analysing the code in detail we were able to guess two out of four tests
this entry uses to tell the 5 languages/flavors apart. Can you find all four?</p>
<p>The way the text is encoded in the output doesn&rsquo;t cease to amaze. Can you tell
why an array of 512 elements is needed?</p>
<h2>Author&rsquo;s comments:</h2>
<p>Fuuko is a sea star generator. Feed her some input through stdin to
get lots of sea star patterns in stdout.</p>
<pre><code>gcc -O3 -std=c90 fuuko.c -lm -o fuuko_c90
echo IOCCC | ./fuuko_c90 &gt; output_c90.c
</code></pre>
<p>If you compile with a C99 compiler instead of C90, the sea stars will
have eyes.</p>
<pre><code>gcc -O3 -std=c99 fuuko.c -lm -o fuuko_c99
echo IOCCC | ./fuuko_c99 &gt; output_c99.c
</code></pre>
<p>Don&rsquo;t like sea stars? Use a C++98 compiler to get dango instead.</p>
<pre><code>g++ -O3 -std=c++98 fuuko.c -lm -o fuuko_cpp98
echo IOCCC | ./fuuko_cpp98 &gt; output_cpp98.c
</code></pre>
<p>Don&rsquo;t like dango either? Use a C++11 compiler to get just circles (or
swiss cheese, if you prefer that).</p>
<pre><code>g++ -O3 -std=c++11 fuuko.c -lm -o fuuko_cpp11
echo IOCCC | ./fuuko_cpp11 &gt; output_cpp11.c
</code></pre>
<p>Don&rsquo;t like any of these patterns? Use a C11 compiler and there will be
no extra patterns.</p>
<pre><code>gcc -O3 -std=c11 fuuko.c -lm -o fuuko_c11
echo IOCCC | ./fuuko_c11 &gt; output_c11.c
</code></pre>
<p>Regardless of which of these C/C++ dialects you choose, the output
will all be valid C90 code that reproduces original input on stdout,
filled with pointer dereferences (C stars).</p>
<p>Next time people ask you for a few pointers on C, you can run their
question through Fuuko and give them pointers all day long.</p>
<h3>Compatibility</h3>
<p>Fuuko has been tested under these environments:</p>
<ul>
<li>gcc 4.9.3 on Cygwin</li>
<li>gcc 4.9.2 on Linux</li>
<li>gcc 4.8.4 on Linux</li>
<li>gcc 4.6.3 on Linux (doesn&rsquo;t support C11 nor C++11)</li>
<li>gcc 4.3.5 on JS/Linux</li>
<li>clang 3.5.2 on Cygwin (doesn&rsquo;t work with optimization enabled,
probably cygwin bug)</li>
<li>clang 3.5.0 on Linux</li>
<li>clang 3.4.1 on Linux</li>
<li>tcc 0.9.25 on JS/Linux (C99 only)</li>
</ul>
<h3>Features</h3>
<p>The most obscure parts are in detecting the subtle differences in
different dialects. The standard committees put a lot of effort into
avoiding &ldquo;quiet changes&rdquo;, but Fuuko is still able exploit a few of
those. It should be an interesting exercise for the reader to figure
how she did it.</p>
<p>Output patterns are usually random (except for C11). The built-in
random number generator is seeded using ASLR. On systems where ASLR
is not so random (such as cygwin), you can introduce randomness by
changing number of command line arguments to Fuuko.</p>
<p>Output is somewhat robust: corruption on most of the lines will
usually result in a compiler warning. This is because the output is
vastly redundant: For ~1K of input, expect output to be on the order
of ~1MB, and take ~500MB of RAM to compile.</p>
<p>CRC32 of source code is embedded in the source code itself.</p>
<p>Process of writing this program is included in spoiler.html</p>
<p>Code layout is inspired by Ibuki Fuuko, for her love of sea stars.</p>
<hr />
<TABLE><TR>
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2016,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>