"...all N-Queen problem comes to mere 8 lines of code"<p>If you are optimizing in LOC, it can come down to basically a single expression; of course that's not a reason to write it as a one-liner:<p><pre><code> def n_queen(n):
return (p for p in itertools.permutations(xrange(n))
if all(j-i != abs(p[i] - p[j])
for i in xrange(n - 1)
for j in xrange(i + 1, n)))</code></pre>
This is actually a rather poor way to solve n-queens. Consider those boards that have a queen in the first space of the first row and the second space of the second row. These two queens can attack each other, so no such board is a solution. However, this method will still go through every such board. On the other hand, a backtracking style solution, which builds up the board row by row, will backtrack after the second queen, thus skipping all these boards.
Pypy is very fast, but to me what's way more significant about pypy is that more than being just interpreter, it's a toolchain for writing other interpreters that automatically generates a JIT compiler for you. I'd really be interested to see what sort of performance you could get writing interpreters for other languages in RPython.
I think this is an example where C++ really shines. The code is not much longer (44 vs 33 lines, although the output in python version is much nicer) than the python code and on my computer it is about 140x faster than python 2.7.1.
The most interesting observation from my point of view is that the author sped up PyPy with a simple manual optimization. This means that PyPy still has even more potential for optimization.