Dancing Queens
(Challenge added 621 days ago.)
How many moves can the queens make?
The Problem
In this challenge, you are given a chessboard containing a number of queens. You should examine the board and work out how many different moves are possible, remembering that a queen can move horizontally, vertically and diagonally on a chessboard.
For example, a queen in the top-left corner of a board (Q = queen, _ = empty square)
Q_______ ________ ________ ________ ________ ________ ________ ________
can move to any of the seven squares below, any of the seven squares to the right or to any of the seven squares leading diagonally away to the bottom right. We are looking for 21 as the answer in this case.
A slightly more complicated example :
Q_______ _Q______ ________ ________ ________ ________ ________ ________
Here, the queen in the corner can move to any of the 14 squares horizontally or vertically from that position, but is blocked from going diagonally. The other queen can move to one square up, one square left, one square down-left, six squares down, six squares right, six squares diagonally down and right and one square up and right, a total of 22. So, the answer we're looking for in this puzzle is 36.
More Information
- The board will be given to your program on stdin. The board is given on eight lines, each separated by a newline. Each line will be eight characters long (Excluding the newline), with each character being either a uppercase Q to denote a square containing a queen or an underscore (
_) to denote an empty square. - There will be a minimum of 1 queen on each board, and a maximum of 11.
- Your program should print the number of moves possible on the supplied board.
- Your code will run 7 times for each submission. It will need to pass all 7 runs for it to be deemed successful.
More Examples
As mentioned above, your program will be run seven times. The same diagrams will be given for the first three runs. You can view the input and the expected output by clicking the links below.
For the 5th, 6th and 7th run, your program will receive a different board setup. Click here to see an example, random board. Reload the page to get a new diagram.
Thanks
Once again, thanks to Mark Byers for suggesting and submitting this challenge!
