0:00
Hello.
00:02
For problem 20, you're asked to write a program that will display all of the solutions to the eight queens puzzle.
00:13
So if you solved exercise 18, you found one solution.
00:19
And depending on how you wrote your program for problem 18, you might have to make some modifications.
00:25
I know i did.
00:27
So we'll start with defining an implementation.
00:30
List here of results which will hold all of the results.
00:35
We of course need to determine whether or not a queen can be placed in any given place.
00:42
So i've started by writing a function here called attack that determines if a queen placed on the board is in danger of attack.
00:51
We first checked vertically and horizontally to see if there are other queens on the board either in the vertical or horizontal direction.
01:02
And if there are, then you return true.
01:06
So it's true that you're in danger of attack.
01:10
And we'll do the same diagonally.
01:12
So we'll check the diagonals and see if there is a queen.
01:17
If there is a queen, we will again return.
01:20
That means that that location on the board is equal to one.
01:23
We'll return true.
01:25
If nothing is true, then we'll return false.
01:29
Indicating that the queen is not in danger of attack.
01:34
For solving the puzzle itself, we want to use a backtracking type method.
01:42
So for our given board, we will place a queen in a column and then we'll try all of the rows...