International Obfuscated C Code Contest


The International Obfuscated C Code Contest is a computer programming contest for the most creatively obfuscated C code. Held annually in the years 1984–1996, 1998, 2000, 2001, 2004–2006, 2011–2015 and then in 2018, it is described as "celebrating syntactical opaqueness". The winning code for the 25th contest, held in 2018, was released in May 2018.
Entries are evaluated anonymously by a panel of judges. The judging process is documented in the competition guidelines and consists of elimination rounds. By tradition, no information is given about the total number of entries for each competition. Winning entries are awarded with a category, such as "Worst Abuse of the C preprocessor" or "Most Erratic Behavior", and then announced on the official IOCCC website. The contest states that being announced on the IOCCC website is the reward for winning.

History

The IOCCC was started by Landon Curt Noll and Larry Bassel in 1984 while employed at National Semiconductor's Genix porting group. The idea for the contest came after they compared notes with each other about some poorly written code that they had to fix, notably the Bourne shell, which used macros to emulate ALGOL 68 syntax, and a buggy version of finger for BSD. The contest itself was the topic of a quiz question in the 1993 Computer Bowl. After a hiatus of five years starting in 2006, the contest returned in 2011.
Compared with other programming contests, the IOCCC is described as "not all that serious" by Michael Swaine, editor of Dr. Dobbs.

Rules

Each year, the rules of the contest are published on the IOCCC website. Rules vary from year to year and are posted with a set of guidelines that attempt to convey the spirit of the rules.
The rules are often deliberately written with loopholes that contestants are encouraged to find and abuse. Entries that take advantage of loopholes can cause the rules for the following year's contest to be adjusted.

Obfuscations employed

Entries often employ strange or unusual tricks, such as using the C preprocessor to do things it was not designed to do, or avoiding commonly used constructs in the C programming language in favor of much more obscure ways of achieving the same thing. Two contest winners generated a list of prime numbers using the C preprocessor "spectacularly", according to Dr. Dobbs. Some quotes from 2004 winners include:
Contributions have included source code formatted to resemble images, text, etc., after the manner of ASCII art, preprocessor redefinitions to make code harder to read, and self-modifying code. In several years, an entry was submitted that required a new definition of some of the rules for the next year. This is regarded as a high honor. An example is the world's shortest self-reproducing program. The entry was a program designed to output its own source code, and which had zero bytes of source code. When the program ran, it printed out zero bytes, equivalent to its source code.
In the effort to take obfuscation to its extremes, contestants have produced programs which skirt around the edges of C standards, or result in constructs which trigger rarely used code path combinations in compilers. As a result, several of the past entries may not compile directly in a modern compiler, and some may cause crashes.

Examples

Within the code size limit of only a few kilobytes, contestants have managed to do complicated things – a 2004 winner turned out an operating system.

Toledo Nanochess

Toledo Nanochess is a chess engine developed by Mexican Oscar Toledo Gutiérrez, a five-time winner of the IOCCC. In accordance with IOCCC rules, it is 1255 characters long. The author claims that it is the world's smallest chess program written in C.
The source code for Toledo Nanochess and other engines is available.
Because Toledo Nanochess is based on Toledo's winning entry from the 18th IOCCC, it is heavily obfuscated.
On February 2, 2014, the author published the book Toledo Nanochess: The commented source code, which contains the fully commented source code.
As of February 7, 2010, it appears to be one of only two chess engines written in less than 2 kilobytes of C that are able to play full legal chess moves, along with Micro-Max by Dutch physicist H. G. Muller. In 2014 the 1 kilobyte barrier was broken by Super Micro Chess – a derivative of Micro-Max – totaling 760 characters. There is also a smaller version of Toledo's engine, the Toledo Picochess, consisting of 944 non-blank characters.
Source code excerpt

B,i,y,u,b,I,*G=I,x=10,z=15,M=1e4;X

w){g=q|p+a-S?0:I+S _!r&(q|A<3||g)||(r+1&z^y)>9&&q|A>2){_ m=!(r-2&7))P G1=O,

K;J=n=o&z;E=I&z;t=q|E-7?n:

Pi

Below is a 1988 entry which calculates pi by looking at its own area:

  1. define _ -F<00||--F-OO--;
int F=00,OO=00;mainF_OO

Flight simulator

Another example is the following flight simulator, the winner of the 1998 IOCCC, as listed and described in Calculated Bets: Computers, Gambling, and Mathematical Modeling to Win and shown below:

  1. include
  2. include
  3. include
  4. include
double L,o,P
,_=dt,T,Z,D=1,d,
s,E,h= 8,I,
J,K,w,M,m,O
,n,j=33e-3,i=
1E3,r,t, u,v,W,S=
74.5,l=221,X=7.26,
a,B,A=32.2,c, F,H;
int N,q, C, y,p,U;
Window z; char f
; GC k; main

This program needs the following command line on a Linux system to be compiled:

cc banks.c -o banks -DIT=XK_Page_Up -DDT=XK_Page_Down \
-DUP=XK_Up -DDN=XK_Down -DLT=XK_Left -DRT=XK_Right \
-DCS=XK_Return -Ddt=0.02 -lm -lX11 -L/usr/X11R6/lib