Thursday Code Puzzler: N-Queens Revisited
Join the DZone community and get the full member experience.Join For Free
It's code puzzler day, but today we'll do something a little different. I was looking back at some of the previous puzzlers - we've been through quite a few since we started the series in April 2012. I thought it might be fun to review the first puzzler : the N-Queens problem.
In case you're unfamiliar with the problem, here's the summary we posted:
One of the classic programming challenges. What you need to do is place 8 queens on an 8x8 chess board in a way that no two queens attack each other. For those who don't play chess, this means that no two queens can be on the same row, column or diagonal. Sounds simple? Go!
If you check the comments , you'll see there are a couple of solutions in there. However, I know we have gained some regular visitors to our weekly puzzler spot since then, so I'd like to invite everyone to take another shot at it. Is there any improvements that can be made to the solutions that were submitted? Can you write a solution that will get the problem solved in a lower execution time?
Opinions expressed by DZone contributors are their own.