Author: Gerd Isenberg
Date: 09:02:42 04/10/03
Go up one level in this thread
On April 10, 2003 at 06:20:02, Albert Bertilsson wrote:
>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");
>>}
>Sorry about the empty post...
>
>Hmm... someone with top notch C knowledge obviously wrote this...
>Some notes though:
>With the VC 7 kompiler the board is printed in the wrong way, the Queen
>positions are marked with spaces, and white squares are marked with 'Q'.
>
>There are some strange stuff in the code like:
>... &&(!k&&!!printf(2+"\n ...
>Two following !!, I don't see the point of that.
>... &&(!k&&printf(2+"\n ...
>Gives the same result when I compile it.
>
>It was quite easy to simplify the code by breaking it att each ',' sign. But
>still some lines are very long and no line except for the main and the printf
>makes any sense to me.
>
>I doubt that the author could really understad this himself without really
>spending some hours analyzing it.
>
>It is still an amazing example of what computers can do with a small set of
>instructions, and a good example of how C-code can be messed up!
Yes, amazing. I guess the double boolean not maps all integers not equal zero
(printf may return negative values in case of error, otherwise the number of
characters printed) to "true" or "1" and zero to "false".
!!printf ("\n\n%c" + 2 - (!l<<!j), /* format */
"# Q" [l^v ? (l^j)&1 : 2] /* chracter to print */)
Regards,
Gerd
>
>/Regards Albert
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.