/eight_queens

Gets a solution to the Eight Queens Problem. Written in Python.

Primary LanguagePython

eight_queens

Gets a solution to the Eight Queens Problem. Written in Python.

Usage:

python solve_eight_queens.py

http://en.wikipedia.org/wiki/Eight_queens_puzzle

I decided to do this after seeing this tweet thread: https://twitter.com/mperham/status/608750153307017216

and becoming curious if I could come up with a software solution.

It took 1 hour, 25 minutes for me to write code that correctly produces the following solution:

array([[1, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 2, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 3],
       [0, 0, 0, 0, 0, 4, 0, 0],
       [0, 0, 5, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 6, 0],
       [0, 7, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 8, 0, 0, 0, 0]])       

Image of solution

(it only takes a couple of seconds to run the code itself!)