Interesting 8x8 chess board counting problem

  • #61
To jbriggs444.
Good, good, good.
So in every element of the array, there is a number. And the number represents how many path to the solution. In the end it's a matter of memory vs process. I remember the case once in finding prime number.
Well, well, well, jbriggs444, you never cease to amaze me!.
I always find good explanations from you!.
I don't know whether you're a good scientist, physicist or a good computer programmer.
But one thing for sure, you're a damn GOOD TEACHER!. Bravo!
 
Mathematics news on Phys.org
  • #62
#!/usr/bin/perl
#
# Iterative approach. Populate n by n array
#
Foolish of me. Of course, perl!
 
  • #63
Code:
for $i ( 1 .. $row-1 ) {
  $ways = $ways + $count[$i][$column];
};
for $i ( 1 .. $column-1 ) {
  $ways = $ways + $count[$row][$i];
};
I'm sorry jbriggs444,
I think that line of code should be changed to:
Code:
if ($Row>1) $ways = $ways + $count[$Row-1][$column];
if ($Col>1) $ways = $ways + $count[$Row][$column-1];
Thanks for your explanations!

For QueenMode

Code:
if ($Row>1) $ways = $ways + $count[$Row-1][$column];
if ($Col>1) $ways = $ways + $count[$Row][$column-1];
if ($QueenMode && ($Row>1) && ($Col>1)) $ways = $ways + $count[$Row-1][$column-1];

Ahhh, PhysicsForums is suck!
Why there's no "Pascal" option in insert code. From all languages, they have FORTAN! :smile:
 
  • #64
Stephanus said:
Code:
for $i ( 1 .. $row-1 ) {
  $ways = $ways + $count[$i][$column];
};
for $i ( 1 .. $column-1 ) {
  $ways = $ways + $count[$row][$i];
};
I'm sorry jbriggs444,
I think that line of code should be changed to:
Code:
if ($Row>1) $ways = $ways + $count[$Row-1][$column];
if ($Col>1) $ways = $ways + $count[$Row][$column-1];
That depends on what problem you are trying to solve. The program correctly solves the problem it was intended to solve. That problem being finding the number of distinct sequences of [eastward and northward] rook moves that can go from one corner to the other of an i by j chessboard.

If you want to determine the number of paths, the recurrence does indeed become much simpler. The distinction between the number of paths and the number of sequences of moves has been pointed out multiple times in this thread.
 
  • Like
Likes   Reactions: Stephanus
  • #65
You are on 1,1 to get on 8,8 you have to move 7 steps along x-axis and 7 steps along the y axis. Since we can't "back off" therefore whenever we will make a move we will add "1" to the value of x or that of y. Let's write "x" for move along x axis, and "y" for that along y axis. Now each possible path can be associated uniquely with a sequence of seven x's and seven y's. e.g., xxxyyyxyxyxyyx is one the possible path, fortunately there is one to one correspondence between the possible arrangement and no. of paths, now finding former is simple its just purmutation of 14 thing seven of one kind and rest of other kind, this no. is just equal to 14!/7!*7!.
On solving gives 3432.
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
10K
  • · Replies 13 ·
Replies
13
Views
3K
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
4
Views
6K
  • · Replies 25 ·
Replies
25
Views
5K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
8
Views
18K