Knight , and that of a Queen .
Define a Galloping Queen as a chess piece whose legal move is that of aIn how many ways can you place 4 non-attacking Galloping Queen's on an 8 × 8 board?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
First of all we define a safe function that takes a list of queens and checks if they are attacking each other. The function generates all the squares that are under attack by a queen q i and then checks if q i + 1 is standing on such a square. The following iteration it will add the squares from q i + 1 and check q i + 2 . Since all the moves are symmetric we don't have to check if q i is attacking q i − 1 since q i would already be under attack.
In this solution all positions are tested, even stacked queens but stacked queens always result in a attack.
The order of the queens doesn't matter but it's easier to double count and the remove duplicates. Since there are 4 queens we can arrange them in 4 ! = 2 4 ways and thus divide by 24 at the end.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
Awesome problem, thanks!
How fast is your code?
Problem Loading...
Note Loading...
Set Loading...
I just go through every possible combination of 4 positions on the board, check if they are non-attacking and count them.