473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

8-queen problem

cj
Hello, I am also looking for information how to write code which finds
solutions to 8-queen problem (position 8 queens on a chess board, or N
queens on a N*N board, so that they do not hit each other). Any input would
be highly appreciated.

Thanks,
C++J
Jul 22 '05 #1
5 9261
cj wrote:

Hello, I am also looking for information how to write code which finds
solutions to 8-queen problem (position 8 queens on a chess board, or N
queens on a N*N board, so that they do not hit each other). Any input would
be highly appreciated.


That's not the way it works in this newsgroup.
If you have problems with your homework, do an attempt
at it until you get stuck. Then post specific questions
about the problem you encounterd with the code you already
have.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #2

"cj" <cj@yahoo.com> wrote in message
news:c2******************************@news.teranew s.com...
Hello, I am also looking for information how to write code which finds
solutions to 8-queen problem (position 8 queens on a chess board, or N
queens on a N*N board, so that they do not hit each other). Any input would be highly appreciated.

Thanks,
C++J


I guess it's safe to say you didn't try googling for "8 queens"

Rufus
Jul 22 '05 #3
cj wrote:
Hello, I am also looking for information how to write code which finds
solutions to 8-queen problem (position 8 queens on a chess board, or N
queens on a N*N board, so that they do not hit each other). Any input would
be highly appreciated.

Thanks,
C++J


What kind of information, besides writing the program for you?

A queen can attack in all directions for the length of the board.
One presumes immediately that only one queen can exist per row.

Place the queen on a square in row one.
Place a queen on the second row so that it is in a safe spot.
Place the 3rd queen on the 3rd row so that it is in a safe spot.
And so on.
Place the 8th queen on the 8th row so that it is in a safe spot.
If all 8 queens can be placed, print the board configuration
or minimally, the location of each queen.

Move the 8th queen to a new spot if possible. If possible,
print the configuration and try for another one.
Otherwise, move the 7th queen to a new position on the 7th
row and reposition the 8th queen. Repeat until the first
queen has tried all her positions.

Next time, for help with the algorithm or "how to do it",
try news:comp.programming. Otherwise, post the code that
you are having problems with.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #4
cj wrote:
Hello, I am also looking for information how to write code which finds
solutions to 8-queen problem (position 8 queens on a chess board, or N
queens on a N*N board, so that they do not hit each other). Any input would
be highly appreciated.


#include <cstdio>
int main(void) {
printf("QQ-- -- -- --\n");
printf("-- -- QQ -- \n");
printf(" -- -- -- QQ\n");
printf("-- -- --QQ-- \n");
printf(" --QQ-- -- --\n");
printf("-- -- -- QQ \n");
printf(" QQ -- -- --\n");
printf("-- QQ -- -- \n");
return 0;
}

- Dario
Jul 22 '05 #5
cj wrote:
Hello, I am also looking for information how to write code which finds
solutions to 8-queen problem (position 8 queens on a chess board, or N
queens on a N*N board, so that they do not hit each other). Any input would
be highly appreciated.


Errare humanum est, perseverare diabolicum.
So, obviuosly, the folowing is (one of) the right answer(s):

#include <cstdio>
int main(void) {
printf("QQ-- -- -- --\n");
printf("-- -- QQ -- \n");
printf(" -- -- -- QQ\n");
printf("-- -- --QQ-- \n");
printf(" --QQ-- -- --\n");
printf("-- -- -- QQ \n");
printf(" QQ -- -- --\n");
printf("-- --QQ-- -- \n");
return 0;
}

- Dario
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
4
by: David Morgan | last post by:
Hi This is a really weird problem. We have a website that has been running for about six months with no problems. We have recently moved it to a new server with a new ISP. The server is of a...
11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
7
by: Keith Dewell | last post by:
Greetings! My current job has brought me back to working in C++ which I haven't used since school days. The solution to my problem may be trivial but I have struggled with it for the last two...
117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.