C Board  

Go Back   C Board > Community Boards > Contests Board

Reply
 
LinkBack Thread Tools Display Modes
Old 06-15-2007, 11:51 AM   #1
Captain - Lover of the C
 
Brad0407's Avatar
 
Join Date: May 2005
Posts: 337
8 Queens

Goal of 8 Queens
On an 8 by 8 board, place 8 chess queens so that no queen attacks any other queen. A queen can attack horizontally, vertically, or diagonally.

Contest
Write an algorithm that will find a solution to the 8 queens problem.

Rules
There will be one queen in each column. The algorithm must decide the row that each queen should be in.
[edit]Since this problem lends itself to artifical intelligence, your intelligent agent cannot know anything else about the problem other than the definition. This means that it cannot know the solution. However, heuristics are allowed.[/edit]
The algorithm can place the queens on the board in the correct pattern or it can start with all the queens on the board and move them to the correct pattern. If the algorithm starts with the queens on the board, it must either use an algorithm to place them or start with the queens in random rows in each column.

Judging
I will add this later
__________________
Don't quote me on that... ...seriously

Last edited by Brad0407; 06-15-2007 at 09:38 PM.
Brad0407 is offline   Reply With Quote
Old 06-15-2007, 01:46 PM   #2
aoeuhtns
 
Join Date: Jul 2005
Posts: 581
Your 'rules' don't much sense to me. Here's my solution:
Code:
head (queens 8)
See sig for details.

Edit: here's an alternate solution, in C:
Code:
void queens8(void) {
    puts("[(1,4),(2,2),(3,7),(4,3),(5,6),(6,8),(7,5),(8,1)]");
}
__________________
There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

Last edited by Rashakil Fol; 06-15-2007 at 01:49 PM.
Rashakil Fol is offline   Reply With Quote
Old 06-15-2007, 01:55 PM   #3
Anti-Poster
 
Join Date: Feb 2002
Posts: 1,212
Quote:
Originally Posted by Rashakil Fol View Post
Edit: here's an alternate solution, in C:
Code:
void queens8(void) {
    puts("[(1,4),(2,2),(3,7),(4,3),(5,6),(6,8),(7,5),(8,1)]");
}
I thought of that same solution, but I think he's got it covered in this part:
Quote:
Originally Posted by Brad0407 View Post
If the algorithm starts with the queens on the board, it must either use an algorithm to place them or start with the queens in random rows in each column.
__________________
Rule #1: Every rule has exceptions

Traveller's Dilemma Contest Site - Results posted!
pianorain is offline   Reply With Quote
Old 06-15-2007, 02:27 PM   #4
Crazy Fool
 
Perspective's Avatar
 
Join Date: Jan 2003
Location: Canada
Posts: 2,588
This is the most standard programming languages homework assignment around. I'm surprised the spec doesn't say to write it in Lisp.
Perspective is offline   Reply With Quote
Old 06-15-2007, 03:02 PM   #5
aoeuhtns
 
Join Date: Jul 2005
Posts: 581
Quote:
Originally Posted by pianorain View Post
I thought of that same solution, but I think he's got it covered in this part:
Quote:
If the algorithm starts with the queens on the board, it must either use an algorithm to place them or start with the queens in random rows in each column.
This is where I am not understanding him. What does it mean for an algorithm to start with the queens on the board? Mine doesn't, I guess, so that rule doesn't apply to my algorithm. And if by some definition it did, I am in fact using an algorithm to place the queens ("place the first at (1,4), another at (2,2)," and so on). Unless Brad would care to suggest some unorthodox definition of 'algorithm'...
__________________
There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.
Rashakil Fol is offline   Reply With Quote
Old 06-18-2007, 10:18 AM   #6
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,927
I think he means 'calculation' when he says 'algorithm'. This smells awfully like a homework assignment..

so here is my solution -

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.

oh, and on a 3.2 GHz processor, it will only take a month to find a solution (maybe less), since there are only 178,462,987,637,760 (thats 178 trillion) possibilities, and more than 1 is valid.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet

Last edited by abachler; 06-18-2007 at 10:20 AM.
abachler is offline   Reply With Quote
Old 06-18-2007, 12:13 PM   #7
Captain - Lover of the C
 
Brad0407's Avatar
 
Join Date: May 2005
Posts: 337
Guess maybe this contest was too hard...
If there are no actual attempt in a week, I'll post a solution. Maybe a few.
__________________
Don't quote me on that... ...seriously
Brad0407 is offline   Reply With Quote
Old 06-18-2007, 12:16 PM   #8
Registered User
 
Join Date: Jan 2005
Posts: 7,137
I'm not sure anybody understands what you're asking.
Daved is offline   Reply With Quote
Old 06-18-2007, 12:48 PM   #9
Fear the Reaper...
 
Join Date: Aug 2005
Location: Toronto, Ontario, Canada
Posts: 625
Or, rather, why Rashakil Fol's answer isn't correct.
__________________
Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction
Happy_Reaper is offline   Reply With Quote
Old 06-18-2007, 01:20 PM   #10
Massively Single Player
 
AverageSoftware's Avatar
 
Join Date: May 2007
Location: Buffalo, NY
Posts: 141
This puzzle is straight out of The 7th Guest. The bishop puzzle is much harder, and would make a much better algorithm.

If you haven't played The 7th Guest, a pox upon you!
__________________
There is no greater sign that a computing technology is worthless than the association of the word "solution" with it.
AverageSoftware is offline   Reply With Quote
Old 06-18-2007, 04:46 PM   #11
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,927
Quote:
Originally Posted by Brad0407 View Post
If there are no actual attempt in a week, I'll post a solution. Maybe a few.
Is that when its due?

Quote:
Originally Posted by abachler View Post
it will only take a month to find a solution
I misspoke, theres a simple optimization that lets you brute force it in 40,320 tries or less.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet

Last edited by abachler; 06-18-2007 at 04:56 PM.
abachler is offline   Reply With Quote
Old 06-18-2007, 05:35 PM   #12
Registered Abuser
 
Join Date: Jun 2006
Location: Toronto
Posts: 572
Isn't this problem the "Hello World" of learning recursion? (that and string permutations)
@nthony is offline   Reply With Quote
Old 06-18-2007, 09:30 PM   #13
Captain - Lover of the C
 
Brad0407's Avatar
 
Join Date: May 2005
Posts: 337
abachler, I don't even start college until August and won't be taking an A.I. class for at least a year after that. You jumping to conclusions is slightly insulting and annoying. You got your first solution from 64*63*62*61*60*59*58*57. However, any fool would write the loops like this:
Code:
for (Q1 = 0; Q1 < 57; Q1++)
{	
	for (Q2 = Q1; Q2 < 58; Q2++)
	{
		for (Q3 = Q2; Q3 < 59; Q3++)
		{
			for (Q4 = Q3; Q4 < 60; Q4++)
			{
				for (Q5 = Q4; Q5 < 61; Q5++)
				{
					for (Q6 = Q5; Q6 < 62; Q6++)
					{
						for (Q7 = Q6; Q7 < 63; Q7++)
						{
							for (Q8 = Q7; Q8 < 64; Q8++)
							{
								
							}
						}
					}
				}
			}
		}
	}
}
That's 10.4 billion. Then you realized that when you place the queens, you can do it one column at a time and check that no queens are in the same row giving you 8*7*6*5*4*3*2*1. This can still be easily beaten with a hill-climbing algorithm starting in random places.
__________________
Don't quote me on that... ...seriously
Brad0407 is offline   Reply With Quote
Old 06-19-2007, 06:52 AM   #14
Anti-Poster
 
Join Date: Feb 2002
Posts: 1,212
How is this a contest and not a 'please write this function for me'? How would we compete with one another? The lack of details makes this look exactly like any of the 'do my homework' threads, regardless of an actual lack of assignment.

I think it's safe to say that when there's a wiki page that explains several different methods on how to solve the problem and several alternate variations of the problem that have also been studied, this one's been done. Try making this interesting.
__________________
Rule #1: Every rule has exceptions

Traveller's Dilemma Contest Site - Results posted!
pianorain is offline   Reply With Quote
Old 06-19-2007, 07:03 AM   #15
Tropical Coder
 
Darryl's Avatar
 
Join Date: Mar 2005
Location: Cayman Islands
Posts: 503
Here's some solutions that list all 92 solutions http://www.cppworld.com/forum/index.php?showtopic=852
__________________
SWinC - Simple Windows Class

Last edited by Darryl; 06-19-2007 at 08:44 AM.
Darryl is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
8 Queens, problem with searching 2D array Sentral C++ Programming 35 03-11-2009 04:12 PM
Problems with the eight queens problem Wicket C++ Programming 1 06-12-2008 09:29 AM
8 Queens problem Dashing Boy C++ Programming 14 10-15-2007 12:12 PM
and this is my solution for the 8 queens puzzle negevy C Programming 1 09-01-2005 11:45 AM
8 Queens PutoAmo C Programming 2 03-24-2003 04:45 AM


All times are GMT -6. The time now is 06:15 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22