How do you put 8 queens on a chessboard so that they won't capture each other?
How do you put 8 queens on a chessboard so that they won't capture each other?
-We're living in a illusion!
-Ok, if that's what you think!
Being on a programming forum and all, you could write a program that finds the answer for you...
Or look below:
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Won't the top and bottom-most queens capture each other?
Put on 8 kings so they're busy?
Put 4 queens on opposite sides of the board and offset them 1 square to the side. At least using the already posted board, that works.
I don't think it's possible.
Golfinguy,
Do you mean having 4 queens on the same vertical line? Because that clearly won't work.
This one actually works. (There are 92 working solutions)
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
You could create a program to find the solution using backtracking.... Similar to solving a maze problem.. I have to use something like this when i start coding my chess games single player part..
Gee, how could I miss that one???Originally posted by minesweeper
Won't the top and bottom-most queens capture each other?
And I thought I checked em all....
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Never mind. I was thinking that 4 of the queens were on the same team.Originally posted by minesweeper
Golfinguy,
Do you mean having 4 queens on the same vertical line? Because that clearly won't work.
And if you want how I calculated it, here ya go.
Warning
This code is uncommented, and basically contest-style code.
Code:#pragma warning( disable: 4530 ) #include <fstream> using namespace std; #define MAXSIZE 13 bool col[ MAXSIZE ]; bool updiag[ MAXSIZE * 2 ]; bool downdiag[ MAXSIZE * 2 ]; ifstream in("checker.in"); ofstream out("checker.out"); int n = 0; int numoutputed = 0; void outputsoln( int *row ) { for( int i = 0; i < n; i++ ) { if( i != 0 ) out<<" "; out<<row[i] + 1; } out<<endl; } int calcnum( int i, int *row ) { int sum = 0; if( i == n ) { outputsoln( row ); return 1; } for( int j = 0; j < n; j++ ) { if( !col[ j ] && !updiag[ i + j ] && !downdiag[ i - j + n ] ) { col[ j ] = true; updiag[ i + j ] = true; downdiag[ i - j + n ] = true; row[i] = j; sum += calcnum( i + 1, row ); col[ j ] = false; updiag[ i + j ] = false; downdiag[ i - j + n ] = false; } } return sum; } int main( void ) { int rows[ MAXSIZE ]; in>>n; out<<calcnum( 0, rows )<<endl; return 0; }
Last edited by XSquared; 04-20-2003 at 06:57 PM.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie