A common riddle in the homework of A.I courses homework is this:
Given an NxN board, you need too arrange N queens such that no queen threatens any other queen.
Of course I write about it because I got this question in the homework of my Intro to A.I course.
The algorithm that solves this riddle efficently is a random and greedy:
Since there are N rows and N queens, there must be a queen in each column (why?),
so we put a queen in each row, but we also need to pick a row for each queen.
the idea is to randomize the rows at the begining, and then, in each iteration move one queen that reduces the number of threatened queens by a maximum.
We do it in each iteration, until the number if threatened queens reach 0, or we get to a situation where we can’t improve any more, because we had a bad start - so we start over, randomizing locations again, and doing the whole thing again, until the queens a safe spot.

The question was not algorithmic but implementational, the algorithm was desribed in the question very clearly, I only need to pick a language and implement it.
unlike my previous assignment, where I choose Prolog to implement Sudoku, which took a long time and brought questionable results, this time I decided to go for the home language - Java.
in about an hour it was written, except it didn’t work - sometimes the algorithm stuck in an infinite loop.
initially I printed the board to the console, but I quickly realized I wont get far this way:
its very hard to detect repeating patterns when they are printed as text, and its also hard to see if the queens threatens diagonaly.
I decided to do wheat I do well, and wrote a User interface that show a simulation of the algorithm, and with it I found and fixed the bugs.
I thought to myself, If I have got this far, I might as well invest some more and make it more useful:
I turned it into an Applet, to allow running it also in the browser, and added a few buttons to control the simultion.
this is the result:
Try to play with it, every time it gets stuck the background turns red and it randomize positions again.
Note that you can solve very big boards with it.
more things to notice are that there is a problem with small board (how small?) and that every time it gives a different solution because the start is random.
the applet is here, the code is included.