mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Correct grammar in backtracking/n_queens_math.py (#4869)
This commit is contained in:
parent
6341f351aa
commit
31b34af9fa
@ -1,7 +1,7 @@
|
|||||||
r"""
|
r"""
|
||||||
Problem:
|
Problem:
|
||||||
|
|
||||||
The n queens problem is of placing N queens on a N * N chess board such that no queen
|
The n queens problem is: placing N queens on a N * N chess board such that no queen
|
||||||
can attack any other queens placed on that chess board. This means that one queen
|
can attack any other queens placed on that chess board. This means that one queen
|
||||||
cannot have any other queen on its horizontal, vertical and diagonal lines.
|
cannot have any other queen on its horizontal, vertical and diagonal lines.
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ So if we use an array and we verify that each value in the array is different to
|
|||||||
other we know that at least the queens can't attack each other in horizontal and
|
other we know that at least the queens can't attack each other in horizontal and
|
||||||
vertical.
|
vertical.
|
||||||
|
|
||||||
At this point we have that halfway completed and we will treat the chessboard as a
|
At this point we have it halfway completed and we will treat the chessboard as a
|
||||||
Cartesian plane. Hereinafter we are going to remember basic math, so in the school we
|
Cartesian plane. Hereinafter we are going to remember basic math, so in the school we
|
||||||
learned this formula:
|
learned this formula:
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ This formula allow us to get the slope. For the angles 45º (right diagonal) and
|
|||||||
See::
|
See::
|
||||||
https://www.enotes.com/homework-help/write-equation-line-that-hits-origin-45-degree-1474860
|
https://www.enotes.com/homework-help/write-equation-line-that-hits-origin-45-degree-1474860
|
||||||
|
|
||||||
Then we have this another formula:
|
Then we have this other formula:
|
||||||
|
|
||||||
Slope intercept:
|
Slope intercept:
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ we would have:
|
|||||||
|
|
||||||
y - mx = b
|
y - mx = b
|
||||||
|
|
||||||
And like we already have the m values for the angles 45º and 135º, this formula would
|
And since we already have the m values for the angles 45º and 135º, this formula would
|
||||||
look like this:
|
look like this:
|
||||||
|
|
||||||
45º: y - (1)x = b
|
45º: y - (1)x = b
|
||||||
@ -71,7 +71,7 @@ look like this:
|
|||||||
y = row
|
y = row
|
||||||
x = column
|
x = column
|
||||||
|
|
||||||
Applying this two formulas we can check if a queen in some position is being attacked
|
Applying these two formulas we can check if a queen in some position is being attacked
|
||||||
for another one or vice versa.
|
for another one or vice versa.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user