Eight Queens

There are ninety-two ways to place eight queens on a standard chess board such that no queen can take any other queen, but what are they? This is the question that I have spent the last three days pondering. I surely could have ran to google crying, but what fun is in that? Being the weirdo that I am, I took it upon myself to think up a fairly good algorithm and then put it to code. If you value your sanity, you should skip reading the rest of this post…

The algorithm I decided to use is a simple breadth-first search algorithm. It begins in the first column of the chessboard, by placing a queen in the first available row. In each subsequent column, a queen is placed in the first available row. When a column that doesn’t have any ‘available’ spaces is encountered, the queen in the previous column is moved to the next available row. When a queen is successfuly placed in the eigth column, the column is cleared and the queen in the (n-1)th column is moved to the next available row. When the first column is reached, and a queen cannot be placed (because there are no rows left to test), all of the solutions have been found. The bit of PHP I threw together to do this for me can successfuly find all ninety-two solutions to the eight queens problem in .27 seconds. It took me five periods to find the first one by hand…

And now for that anecdote I said I might include. Josephus and forty other jewish people were trapped in a cave surrounded by romans. Rather than give themselves up to the romans, all but Josephus and one other man resolved to committ suicide. Josephus proposed that this be done in an orderly fashion: they were to stand in a circle and kill every third person. The remaining person would then committ suicide. Josephus lived to tell the story…

6 Responses to “Eight Queens”

  1. Sean Says:

    A great example of how maths can be very useful in everyday life, without that algorithm you could have spent weeks working that out, and people think i’m crazy having 10 lessons(1 hour long each) of maths a week.

  2. kayla Says:

    when the hell did you change your header?

    i’ll go click links for you now. :)

  3. kayla Says:

    you’re links, by the way, are all about suicide…

    i clicked one, and it was fucking scary. it was all about god and stuff, and if you clicked on the wrong/sarcastic answer, or the “I don’t believe in God” “I am God” or whatever, then it would say “Go back and try that again”.

    wtf?

  4. Bowser Says:

    Hmm… Those ads are targeted. The fact that suicide ads are relevant to me is pretty scary.

    Thanks! You’re awesome!

  5. Joe Says:

    w00t Kayla saw my logo…teh coolz0rz right?

  6. Joe choiniere Says:

    Greg….you saved your form info in my computer and it showed up in above comment..

Leave a Reply