Over a million developers have joined DZone.

Thursday Code Puzzler: N-Queens Revisited

· Java Zone

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

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? 



Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}