Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: 8 queens problem meets obfuscated C programming

Author: Randall Shane

Date: 08:05:50 04/10/03

Go up one level in this thread


On April 09, 2003 at 23:56:54, Russell Reagan wrote:

>So...who wants to explain how this works? I don't know how it works, but it
>finds all of the solutions to the 8 queens problem.
>
>#include <stdio.h>
>int v,i,j,k,l,s,a[99];
>void main(void){
>for(s=8;*a-s;v=a[j*=v]-a[i],k=i<s,j+=(v=j<s&&(!k&&!!printf(2+"\n\n%c"-(!l<<!j),"
>#Q"[l^v?(l^j)&1:2])&&++l||a[i]<s&&v&&v-i+j&&v+i-j))&&!(l%=s),v||(i==j?a[i+=k]=0:++a[i])>=s*k&&++a[--i]);
> printf("\n\n");
>}

Many obfuscated programs floating around are copies of entries to the
International Obfuscated C Code Contest (www.ioccc.org).

This program is a slightly cleaned-up version of a program that Baruch
Nissenbaum wrote for the contest.  It was the 1990 Best Small Program winner.
Copyright status is not clear to me.

http://www0.us.ioccc.org/years.html#1990 is where it can be found (look under
the entry for 'baruch'.

The original program omitted the #include, the explicit 'int' declaration in the
second line, and the final printf.  It also had a scanf call in place of the
's=8' statement, so that it could handle any size board up to 99.

It's not supposed to be easy to read.  I appreciate the fact that there is no
body for the 'for' loop.




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.