Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Instructions
- NOTE: edmodo is removing the []. Look at the attached txt file for a clear look at the assignment.
- 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.
- Look at the attached image and the links below.
- Hint: to determine whether setting qn = i conflicts with q0 through qn-1
- if qi equals qn: two queens are placed in the same column
- if qi - qn equals n - i: two queens are on same major diagonal
- if qn - qi equals n - i: two queens are on same minor diagonal
- WARNING: do not look for a solution online.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement