The Little Program That Couldn't

Well, I didn't win the 20th IOCCC competition. I thought the below entry -- a one-liner -- had a decent shot; though short, I liked it more than some of my past winners. Perhaps it lost points because it solved a problem (computing primes) that they actively discouraged, or perhaps they just liked the other programs better.

Disappointing, especially in light of the fact that I've been sitting on this program for the last five+ years, after (aggravatingly) missing the announcement for the previous contest.

They tell you not to bother resubmitting previously failed entries, and I don't think that after five years of looking at it I'm going to find any significant way to improve it. So I might as well just post it publicly.

If you want a hint on how it works, check this Foxtrot comic strip which originally inspired it!

Mark Schnitzius
schnitziATgmailDOTcom


Description:

While the task this program performs - generating prime numbers - has been discouraged by the IOCCC judges, I believe this implementation has merits that are worthy of consideration.

It requires a command-line argument -- anything, really, so try this:

./primes blurglecruncheon

It will proceed to print out the prime numbers, at least up to 73 before going haywire. (This is the fault of sizeof(int), not the algorithm; it would happily keep printing out lots more primes if ints were bigger.)

This is a dozen or so characters shorter than the smallest prime number generator I can find on the web. Yet still there is room enough for it to tell you what it's doing, in the first eleven characters. Is this the world's smallest self-documenting program?

The program:

P,R=1,M=3,S;main(s){(P=M+S,M=S,S=s)%++R||printf("%d\n",R),main(P);}