Advertisement
Arbitrator

Untitled

Oct 14th, 2019
7,049
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. Instructions
  2.  
  3. NOTE: edmodo is removing the []. Look at the attached txt file for a clear look at the assignment.
  4. In this exercise, you will solve the classic 8-queens problem: place 8 queens on an 8-by-8 chess board so that no two queens are in the same row, column, or diagonal. There are 8! = 40,320 ways in which no two queens are placed in the same row or column. Any permutation p[] of the integers 0 to 7 gives such a placement: put queen i in row i, column "pi". Your program Queens.java should take an integer command-line argument n and enumerate all solutions to the n-queens problem by drawing the location of the queens in ASCII like the two solutions below.
  5.  
  6. Look at the attached image and the links below.
  7.  
  8. Hint: to determine whether setting qn = i conflicts with q0 through qn-1
  9. if qi equals qn: two queens are placed in the same column
  10. if qi - qn equals n - i: two queens are on same major diagonal
  11. if qn - qi equals n - i: two queens are on same minor diagonal
  12.  
  13. WARNING: do not look for a solution online.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement