Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Thursday Code Puzzler: N-Queens Revisited

DZone's Guide to

Thursday Code Puzzler: N-Queens Revisited

· Java Zone ·
Free Resource

The CMS developers love. Open Source, API-first and Enterprise-grade. Try BloomReach CMS 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? 



BloomReach CMS: the API-first CMS of the future. Open-source & enterprise-grade. - As a Java developer, you will feel at home using Maven builds and your favorite IDE (e.g. Eclipse or IntelliJ) and continuous integration server (e.g. Jenkins). Manage your Java objects using Spring Framework, write your templates in JSP or Freemarker. Try for free.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}