• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

8 queens problem

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to write the 8 queens program using stacks. I am getting one solution to print instead of all the solutions. Also it is only displaying 7 queens and not 8. Help please.




 
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings and welcome to the ranch....

That said, i have a few issues for you to work.

Starting Pedantic mode ---

First you have not implemented the 8 queens problem, but the n queens problem.

That said, if you have researched the problem, then you know you have not sent enough information for us to answer your question - now if you have not researched your problem, then how do you know what all of the solutions are? i.e.: are you supposed to get 92 or 12 solutions? we don't know, so how can we help?

All of that said - since you are solving the n queen problem and you should know by now that 1 queen is a trivial problem (does your code handle this?). and we know that n = 2 and n = 3 have no solutions. So what i would do, if i were you, is to, by hand write down how YOU would solve a 4 queen problem, detailing every change to your stack (or any other data structure) and what you expect for your output.

Then and only then would i run the code, but i would add prints anytime the data structure changes.

Also, there is too much code in your solve method to test easily - break it down and test it before adding to an entire program.

HTH

-steve
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic