Hacker News new | ask | show | jobs
by anitil 60 days ago
That's very cool. I don't quite understand your solution, are you saying that because you used the i:j relationship as a constant it meant you only needed to store positions rather than a whole board? I've never been interested in 8-queens but I'm keen to play with it now
1 comments

Yeah, the key is in how you model it. It's not a chessboard with 64 squares you need to fill some of, it's a permutation of 8 numbers, the location of the one queen in that row.

You still need to get the backtracking correct and there's some minor tricks to work out, but that'll get you up to n=8 working quite well.

Interesting, I'll give it a whirl tonight
To be clear, the digit at position i is the row number of the queen in column i. So 12345678 is every queen along the diagonal (clearly not a solution).

The model (8 different digits representing row in that column) no queen was in the same row or column, by construction. So only the diagonal test remains.