# 8 Queens

Show 80 post(s) from this thread on one page
Page 3 of 3 First 123
• 06-21-2007
abachler
:rolleyes: , but you failed to write the function to the appropriate declaration of

BOOL Solution(unsigned hyper solution_to_check);
• 06-21-2007
Rashakil Fol
Unsigned hyper? What's a hyper? :-) An unsigned long will do just fine; you only need 24 bits to represent solutions somewhat naively, a long long if you represent very naively.
• 06-21-2007
dwks
> Unsigned hyper? What's a hyper? :-)
If you type "unsigned hyper" into google, you can find this: http://www.freesoft.org/CIE/RFC/1832/8.htm
• 06-22-2007
>> but you failed to write the function to the appropriate declaration of
BOOL Solution(unsigned hyper solution_to_check);

When did you ever say that that was the appropriate declaration?
Code:

```BOOL Solution(unsigned hyper solution_to_check) {                int i, j, Queens[8];         for (i = 0; i < 8; i++)         {                 Queens[i] = ((solution_to_check >> (i * 3)) & 7) + (i * 8);         }         for (i = 0; i < 8; i++)         {                 for (j = 0; j < i; j++)                 {                         // Same row                         if ((Queens[i] / 8) == (Queens[j] / 8))                                 return false;                         // Same column                         if (((Queens[i] - Queens[j]) &#37; 8) == 0)                                 return false;                         // Diagonally                         if (abs((Queens[i] / 8) - (Queens[j] / 8)) == abs((Queens[i] % 8) - (Queens[j] % 8)))                                 return false;                 }                 for (j = i + 1; j < 8; j++)                 {                         // Same row                         if ((Queens[i] / 8) == (Queens[j] / 8))                                 return false;                         // Same column                         if (((Queens[i] - Queens[j]) % 8) == 0)                                 return false;                         // Diagonally                         if (abs((Queens[i] / 8) - (Queens[j] / 8)) == abs((Queens[i] % 8) - (Queens[j] % 8)))                                 return false;                 }         }         return true; }```
Brute force (which is still boring):
Code:

```for (unsigned long x = 0; x < 16777216; x++) {         if (Solution(x))         {                 for (i = 0; i < 8; i++)                         printf("(%d,%d) ", i + 1, ((x >> (3 * i)) & 7) + 1);                 printf("\n");                 SolutionCount++;         } }```
• 06-23-2007
dwks
Quote:

>> but you failed to write the function to the appropriate declaration of
BOOL Solution(unsigned hyper solution_to_check);

When did you ever say that that was the appropriate declaration?
Umm, it's your contest, you should be able to choose the appropriate declaration. :)

Besides, BOOL and unsigned hyper are probably very unportable . . .
• 06-24-2007
The Brain
If you want to see 8 queens, why not just go see a Sigfried & Roy show 4 times tee-hee
• 06-25-2007
abachler
Quote:

>> but you failed to write the function to the appropriate declaration of
BOOL Solution(unsigned hyper solution_to_check);

When did you ever say that that was the appropriate declaration?

right here -
Quote:

Originally Posted by abachler
Code:

```x = 0; while(!solution(x)) x++;```
now you just need to write the BOOL solution() function and have it return whether X is a valid solution.

granted I only specified that the function return type BOOL (a.k.a. bool and very portable), but with the possible number of solutions to check being in some cases larger than the maximum value of a 32bit unsigned , it should be obvious that you need x to be hyper, a.k.a. __int64, _int64 , int64 all very portable.
Show 80 post(s) from this thread on one page
Page 3 of 3 First 123