Note from the publisher: You have managed to find some of our old content and it may be outdated and/or incorrect. Try searching in our docs for current information.
We’re growing! David Lowe is officially Circle’s first engineer.
David is also one the winners of the 2012 International Obfuscated C Code Competition. To introduce David, we thought we’d have him discuss his winning entry and how he made it.
The IOCCC rewards obfuscating cool C programs, under some pretty harsh rules. Not only must programs be obfuscated, but they must fit in 2K of source text. By contrast, this post is over 5K!
David’s entry “Conway’s Game of death” is a classic side-scrolling space-ship game, which requires you to dodge cells which grow according to Conway’s Game of Life. An interesting concept, but not as interesting as the process of writing an X11 game in less than 2K. As David describes:
I created the whole thing in just over a week, and did very little else during that week. Even a very small program is hard to keep in my head when it’s been compressed and obfuscated this much! It really makes me realize how much I rely on meaningful variable names, meaningful indentation, etc. Doing it all in a very short time, with very little else going on, is what made this possible for me.
I started with the title, and the basic idea of making the original “game” of Life into an actual game. I also knew I wanted to format the code into Life cells.
It was about 4-5 days to write “the code in a completely straightforward way”. I had to learn basic X11 programming in that time – not something I’m eager to use again. I had very very good test coverage during this phase.
Another 2 days or so to compress it from 9K bytes to under the 2K limit. I made it by just 117 bytes! Compression and obfuscation are pretty closely related, i.e. renaming everything to single-character names, removing unnecessary braces and parens, consolidating as many variable declarations as possible, and so on. I tried to keep the test coverage high as long as possible, so that I could make aggressive changes with confidence, but at the very end of the compressing I started doing things that made testing prohibitively difficult, in particular inlining almost everything.
I was especially fond of one piece of code: the global struct ‘c’, which has a member struct also named ‘c’, whose only member is a char also named ‘c’, leading to the code: “c.c.c[B((x),(y))/8]”.
I kept the indentation and whitespace more-or-less “normal” until the very end. Once it was small enough, I spent a few hours formatting it into the final shape. I had been hoping to organize the final source into a shape that did “something cool” when played in Life, but I basically got lucky with a 14-cell shape which will evolve into a glider in 19 generations. I did this manually: first I mashed everything into a “brick” of code, then broke it into the “cells” you see in the final code.
Since at this point I had no automated test coverage, I made almost no changes other than formatting. I kept compiler warnings and errors cranked to the max all through the process. The code could have been a bit shorter if I’d been willing to give up that safety net :)
“Conway’s game of death” is now available on GitHub, where you can download it, compile it, and play it. Reading through the history is also instructive, if you ever want to compete in the IOCCC yourself. In either case, you should of course follow David on Twitter.
At Circle, David will be mostly focusing on the backend, working on keeping the system scaling with our growth, and building new features to change the face of continuous testing. He started on Monday, and committed code on his first day to fix some email deliverability issues. He has since leveraged some deep Python knowledge to improve our Python support. Fortunately, he has promised not to use his powers of obfuscation for evil.
Welcome David, and congratulations on your impressive victory!