3 ms·
One thing I find cool about n-queens: there's actually a _much_ better algorithm for finding arbitrary valid n-queens arrangements than the well-known backtrack
by kadoban 5y ago
One thing I find cool about n-queens: there's actually a _much_ better algorithm for finding arbitrary valid n-queens arrangements than the well-known backtracking one. You can find answers up to arbitrarily huge boards, into the millions. (backtracking gets impractical not a lot after the traditional 8).
http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.57.4685 http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.57.46...
This paper describes it. Tl;dr though: randomly place queens such that none are on the same row or column, then do kind of a gradient search swapping the rows (but not columns) of queens that reduce the number of conflicts the most.