Thoughts on Perl and Emacs, technology and writing

Eight queens revisited

Jon Harrop spotted that the Ocaml code was calling is_threatened 64515 times compared to the C++ calling is_threatened just 1915 times. I eventually spotted the bug in the C++ code: next_valid_posn was not correctly iterating through the x positions. The fix was straight-forward:

Unfortunately, wordpress has destroyed your code by removing the white-space (and possibly mangling punctuation such as > and <). Even if it hadn’t, I believe the code is not similar to the original as it generates all solutions rather than back-tracking for a single solution so the benchmark would be invalid.