8 queens 1d array backtracking infinite solutions?

Pages: 12
Oct 9, 2013 at 2:11am
hi in this hw problem im supposed to get 92 solutions but i keep getting infinity amount of solutions i have checked my logic and i believe its correct can anyone point me in the right direction thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 #include <iostream>
#include <cstdlib>
using namespace std;
int main () {
int counter = 1;
int q[8];
int c = 0;
int i = 0;
q[0] = 0;
nc: c++;
 if (c == 8) goto print;
 q[c] = -1;
nr: q[c]++;
 if (q[c] == 8) goto backtrack;
 for (i=0; i < c; i++) {
   if (q[i] == q[c] && abs(q[c] - q[i]) == c - i)
goto nr;
}
goto nc;
backtrack: c--;
    if (c == -1) return 0;
goto nr;
print:
cout << "Solution number:" << counter << endl;
      for (int k = 0; k < 8; k++) {
cout << q[k];
}
cout << endl;
counter ++;
goto backtrack;
}
Last edited on Oct 9, 2013 at 3:18am
Oct 9, 2013 at 2:25am
Post the HW problem. This implementation is... the mind boggles.
Oct 9, 2013 at 2:27am
this is the hw problem?
Oct 9, 2013 at 2:28am
What does the problem tell you to do?
Oct 9, 2013 at 2:29am
Complete the 8 queens 1 dimensional array program with backtracking
Oct 9, 2013 at 2:44am
can anyone help?
Oct 9, 2013 at 2:46am
your first problem is you're using goto.
Oct 9, 2013 at 2:47am
lol i know but its required for this hw assignment i have already completed the same one without the goto statement
Oct 9, 2013 at 4:47am
apparently this problem is too difficult for this forum maybe ill try a different website
Oct 9, 2013 at 5:32am
Nobody is going to try and disect your un-indented, obfuscated code. A description like the one you've provided is nowhere near enough to make anyone outside of your programming class understand what you're talking about.
Oct 9, 2013 at 2:56pm
apparently this problem is too difficult for this forum maybe ill try a different website


Your passive-aggressive attempt at reverse psychology is ineffective here.

Yes, perhaps you will have better luck at another website. Though I suspect any other website will tell you the same thing we're telling you.
Oct 9, 2013 at 3:49pm
This does seem tough. I imagine the website you stole that code from wasn't much help either. http://stackoverflow.com/questions/3852077/8-queens-using-one-array
I checked out the Wikipedia article and found a reference to a .pdf that looked pretty good.
http://en.wikipedia.org/wiki/Eight_queens_puzzle
http://www.cl.cam.ac.uk/~mr10/backtrk.pdf
Oct 9, 2013 at 4:49pm
thanks for actually trying to help booradley60 im not sure if its just that people cant read , the code is written in c++ language if u cant understand it then you shouldnt be on this website i just wanted to know if there was something wrong with my alogrithm but forget it
Oct 9, 2013 at 4:53pm
Its fine if you don't like the users on this forum because I'm pretty sure we don't like you either.

Instead of making threats to leave and go to another forum... maybe actually try leaving and going to another forum.

kthxbye


EDIT:

I'm not usually this hostile... but this guy... jeez.
Last edited on Oct 9, 2013 at 4:55pm
Oct 9, 2013 at 4:58pm
and one more thing i didn't steal the code from any website i made it myself, why would i need to do that, it seems pointless, i wont be able to steal codes when im applying for a job so why would i do it now, you guys are just programmers who weren't good enough to get real jobs so you patrol this sites looking for ways to make others as miserable as you but thats not gonna happen, and im not being passive aggressive it just seems like there are alot of people on this website who dont know anything about c++ but i wont go into detail.
Oct 9, 2013 at 5:01pm
I laughed.
Oct 9, 2013 at 5:01pm
thats because your one of them
Oct 9, 2013 at 5:04pm
Yup. You're right. I know absolutely nothing.

It's pretty sad that one of the top contributors on the board knows so little about C++. You should probably leave and go to a board where people are smarter.
Oct 9, 2013 at 5:10pm
just forget it go "help" someone else
Oct 9, 2013 at 5:13pm
Alright, alright. I had my fun. I'll stop trolling now.
Pages: 12