Over a million developers have joined DZone.

Thursday Code Puzzler: N-Queens Revisited

DZone's Guide to

Thursday Code Puzzler: N-Queens Revisited

· Java Zone
Free Resource

Just released, a free O’Reilly book on Reactive Microsystems: The Evolution of Microservices at Scale. 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? 

Strategies and techniques for building scalable and resilient microservices to refactor a monolithic application step-by-step, a free O'Reilly book. Brought to you in partnership with Lightbend.


Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

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


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

{{ parent.tldr }}

{{ parent.urlSource.name }}