Undoc'd Feature?
|
07-03-2022, 07:09 PM
Post: #11
|
|||
|
|||
RE: Undoc'd Feature?
(07-03-2022 06:24 PM)Wes Loewer Wrote: What an interesting little program. I cannot begin to image what it is trying to calculate. Whatever it is doing, it repeats the exact same calculation 1000 times, and a[0] never gets initialized or used. It solve 8-Queen puzzle. (code really need comments!) Code: if (!(t=a[x]-a[--y]) || x-y==abs(t)) { ... a[] is array of 8x8 chess board, a[i] = j → Queen at (i,j) a[x] is the newly placed Queen, a[y] are previously placed Queens, y = 1 .. x-1 Since we placed 1 Queen per row, there is no need to check horizontal attacks. We only need to test vertical attacks (1st test), and diagonal attacks (2nd test) I would have return actual board (8-digit number), instead of steps required to solve it. We could have returned same steps, but not really solved anything ... http://users.rcn.com/liusomers/nqueen_demo/nqueens.html |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)