My (Losing) IOCCC Entry

Once upon a time, in January 1999, I entered the International Obfuscated C Code Contest. I knew I couldn't top many of the past winners (I mean, have you seen them?) but wanted to give it a try, have some geeky fun, and maybe, just maybe, win one of the lesser titles. I didn't, which makes this a pretty pointless webpage, but at least it's not pictures of my dog. (My metaphorical dog, that is. I don't have a dog. I have a cat.)

So anyway, here it is:

#include <sys/types.h>
#include <signal.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

/*
* This program is respectfully dedicated to the
* fine men and women of the 1003.1 (POSIX.1) Working Group.
*/

#define G(a,b) a+b*(1+T(a,b,0)+T(a,b,1)+T(a,b,2))
#define T(a,l,k) (a+!(l-1)*(l+k)>=b[k])
#define C(o,n,f,e,r) (n<0?o<<-n:o>>n)

volatile pid_t dd=0,bd;int bp,dq=0,b[4]={0,0,0,0
},d=0,p,q=0,pb=0;char pq[100 ];unsigned long bb=0;void
dp(int qp){signal(qp,dp);if (!d?(dd|=1<<G(qp,-1))&&0
:qp==dq?(pb=p/8)>strlen(pq)+1 ?0:((pb=G(((C(pq[pb],(8-p
%8-bp),0,0,0)|(pq[pb+1]>>(16- p%8-bp)))&((1<<bp)-1)),1)
),p+=bp):(bb=bb<<bp|G(qp,-1) ,(q+=bp)>=8)?!(q*=(!!(pb
=(bb>>(q-=8,q))&0xFF)),pb)? 0:(putchar(pb),(pb=dq)):
(pb=dq))kill(dd,pb);}int main (int qq,char *qd[]){long
pp;for(pp=-(bd=getpid());time( NULL)<32L*27*25*41*1069&&(
pp==-bd&&(!b[3]||(pp=-pp%209,pp +=!(pp%2),pp+=2*!(pp%103),
pp*=(pp* pp-1)))||pp==721&&(dq>= pb||(dq=G(pb/2,(pp=1))))||
(!(pp-1)&&!(pp=2-qq?(printf("To " "chat" ": %s %d\n",qd[0],(int)bd),
03755):(dd=atoi(qd[1]),pb=0)) )||!pp&&(pb<sizeof(dd)*8||
dd==0||(pp=-dd))||pp==2029&&( dd==0||(pp=-dd))||pp==7&&
(((fgets(pq,sizeof(pq) ,stdin)&&((p=0)||!kill(bd,
dq)))||!feof(stdin))||(kill( dd,SIGKILL),0)));pp==-bd&&
signal(++dq,dp)==SIG_ERR&&(b[ !!b[0]+!!b[1]+!!b[2]]=dq
)||pp>0&&(!(pp%24)&&(dq-=3+( pb=2+(bp=0*(pp=721))))||
!(pp%103)&&(pb*=2,++bp))||! pp&&pb<sizeof(dd)*8&&1<<
pb++&bd&&kill( dd,G(pb-1,1))||
(pp==-dd?(pp= printf("Ready."
"\n")*(d=1)): 0));return(0);}

(Blurring your eyes helps a bit.)

You build it thusly:

cc -o chat chat.c
chmod u+s chat # Please see the comments regarding
# this line under "remarks."

And here are some of the submission comments for the IOCCC judges:

---entry--
[...]
host: Linux
Solaris
SunOS
HP-UX
SCO OpenServer
SGI IRIX
IBM AIX
...and I bet if our DEC Unix box weren't busy running
Windows NT, it would run on that too! :-)
(In general, it should work fine on any system with
an ANSI C compiler and Unixish/POSIX.1 signals.)

---remark---
My entry--titled "chat"--is a chat program, a bit reminiscent of
talk(1) or write(1). That is, two users can use chat as a
conversational conduit. It uses standard Unix/POSIX.1 signals to
transmit messages from one instantiation of the program to another
and vice versa.

It is run in this way: One
party initiates conver-
sation first by launching
the program thusly: ./chat
Printed in response is: To chat: ./chat PID
where PID is the process ID
of chat.

At this point, the party
can either call or e-mail
a second party and ask
them to type in this: ./chat PID
Or they can wait for
somebody to do a ps(1),
note that the first party
is longing to communicate,
and type the command on
their own initiative.

Either way, once the second
party launches the program,
this will appear on both
screens: Ready.

At this point the two
parties may speak to one
another of their desires
and aspirations, discuss
important issues of the
day, exchange vital
information, or just chat
breezily: So tell me again--why are we
using an underfeatured,
undocumented obfuscated program
to talk when our cubicles share
a common half-height wall?
[Return]

Because we support the open-
obfuscated-source movement--
that's why. [Return]

Once all that need be said
has been said, either party
can terminate the conver-
sation by entering the EOF
character, typically Ctrl-D: Oh. Well, gotta go. [Return]
^D


The build file includes a chmod(1) to set the setuid bit on the
executable so that two different non-privileged users can use the
program to chat with one another. Please note that the program
need *not* be owned by root; ownership by any user will suffice.
As such, I hope you will agree that Rule 11 is not violated. If
not, please remove the chmod line and judge the entry as such.


The only comment I'd like to make regarding the source code is
this: The large block comment appearing near the top of the file is
potentially vital to the primary function of the submitted program,
to wit, winning the contest, in that it represents a big suck-up to
one of the judges. All other comments, of which there are none,
may be removed with impunity.

Eventually the list of winners came out and I wasn't on it. So I shrugged it off and went about my life, until, in mid-2000, I started looking for a new job. Since I'm a programmer, some of the places I interviewed with asked for code samples. In addition to more conventional stuff, I'd also send along chat. This backfired a little when one place, whose interview style was basically "We're too sexy for our shirts; you can't possibly be as big a code stud as we are" responded to chat by asking

so what does it do other than exit?

(Would capitalizing the first letter in the sentence have killed you?)

So I scratched my head and the lightbulb went on and I somewhat sheepishly replied

D-oh!  It's been awhile that I've touched this program and
I'd forgotten that, in the spirit of the contest, I had
inserted a gratuitous Y2K bug. If you replace the code
reading...

time(NULL)<32L*27*25*41*1069

...with...

1

...all should work fine.

Now that I think about it, an easier fix would be to turn that less-than into a greater-than. Then it would still have a gratuitous Y2K bug, but it would be a gratuitous inverse Y2K bug. Anyhow, the next I heard from them they offered me the job. I told them no and went to work for this company instead.