Submit an Entry

To enter the challenge, you need to signup or login.

This Challenge's Best Entries [View All]

(View the Overall | Perl | PHP | Python | Ruby leaderboard.)

Rank User Size Language Score [?]
1st tybalt89 71 Perl 10,000 (v3)
2nd flagitious 76 Ruby 9,342 (v10)
3rd ySas 77 Perl 9,220 (v19)
4th shinh 78 Ruby 9,102 (v13)
5th terjek 78 Perl 9,102 (v4)
6th Mr.Rm 79 Perl 8,987 (v1)
7th o0lit3 79 Perl 8,987 (v7)
8th Mark Byers 80 Ruby 8,875 (v10)
9th kinaba 83 Ruby 8,554 (v2)
10th primo 83 Ruby 8,554 (v11)

See who is active in this challenge →

Dancing Queens

(Challenge added 621 days ago.)

How many moves can the queens make?

Discuss This Challenge →

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!