View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
SteveM SteveM is offline
external usenet poster
 
Posts: 133
Default A "chessboard" problem

On Dec 25, 4:16 pm, Joel wrote:
This requires a recursive program. I could write this for you if you like.

The first level of recursion would be to take the first piece and place it
in all 64 locations and make sure no piece is already placed in the cell.
The piece number 1 to 22 is the same as the level.

Then call the same function again with the second piece.

You keep on calling the function over again for 22 times. When you get to
the 22nd level of recursion you save the results.

You end up needing a main program which performs initialization and calls
the recursive routine the for time.

Here is a start. If basically does everything except saves the results
public Dim MySquare(64)
sub main()

for SquareNumber = 1 to 64
MySquare(squareNumber) = 0
next SquareNumber
call recursive(1)

end sub

sub recursive(piece)

for SquareNumber = 1 to 64
if MySquare(squareNumber) = 0 then
MySquare(squareNumber) = piece
if piece = 22 then
'save results
else
call recursive(piece + 1)
end if
'remove piece by placing 0 in square
MySquare(squareNumber) = 0
end if
next SquareNumber

"Mac" wrote:
Say I have a chessboard (8x8=64 tiles, of course) and e.g. 22 pieces; tiles
are numbered 1 through 64); I want to deploy these 22 pieces throughout the
chessboard (black or white tiles don't matter); every time I do this I get a
set of 22 numbers (numbers of the tiles the pieces reside in); I am looking
for code that would generate for me all possible deployments of these 22
pieces (sets of 22 numbers); it should not be too complex but I cannot find a
clue to start off with... Please, please, give me a hint!:-)


If this question is for a class and part of your grade is based on how
creative and efficient your algorithm is, simple exhaustive
enumeration may be too trivial from your prof's point of voice. (The
"C" solution." you may want consider symmetries that are are part of
the layout. (The "A" solution?) For example, all of the placements on
one half of the board have a complement on the other half. So rather
than exhaustive enumeration, you can solve for one symmetric area and
immediately write out the complement of each solution. Black/White,
{even/odd), the diagonal halves, etc are other symmetries that you may
be able to exploit. Now that I think about it, a one half enumeration
of all combinations with complement capture is the probably best way
to go. I suppose a math guy who know combinatorics better I than
could help you frame out a fewest iterations solution strategy.

Good Luck,

SteveM