marksman95
- 16
- 2
An elementary path (without repeating any of the squares) from (1,1) to (8,8)
I Think the length is 62. This is even number of square so I think we can go through all square except one. this is my path:marksman95 said:An elementary path (without repeating any of the squares) from (1,1) to (8,8)
Stephanus said:For 8 by 8 board, Rook: 3432, Queen: 48639
For 10 by 10 board, Rook: 48,620, Queen: 1,462,563
For 16 by 16 board it takes lot of time. I stop the program. That's where math beats the computer.
#!/usr/bin/perl
#
# Iterative approach. Populate n by n array
#
$limit = 16;
for $row ( 1 .. $limit ) {
for $column ( $1 .. $limit ) {
if ( $row == 1 && $column == 1 ) {
$ways = 1
} else {
$ways = 0;
for $i ( 1 .. $row-1 ) {
$ways = $ways + $count[$i][$column];
};
for $i ( 1 .. $column-1 ) {
$ways = $ways + $count[$row][$i];
};
};
$count[$row][$column] = $ways;
};
};
for $diagonal ( 1 .. $limit ) {
print "$diagonal: $count[$diagonal][$diagonal]\n";
};
We are getting away somewhat from the subject matter of this thread. The programming language is called Perl. The only reason I used Perl was that it was handy. As the old saying goes, real programmers can write Fortran in any language.Stephanus said:Btw, what is your programming language called?
Foolish of me. Of course, perl!#!/usr/bin/perl
#
# Iterative approach. Populate n by n array
#
for $i ( 1 .. $row-1 ) {
$ways = $ways + $count[$i][$column];
};
for $i ( 1 .. $column-1 ) {
$ways = $ways + $count[$row][$i];
};
if ($Row>1) $ways = $ways + $count[$Row-1][$column];
if ($Col>1) $ways = $ways + $count[$Row][$column-1];
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];
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.Stephanus said:I'm sorry jbriggs444,Code:for $i ( 1 .. $row-1 ) { $ways = $ways + $count[$i][$column]; }; for $i ( 1 .. $column-1 ) { $ways = $ways + $count[$row][$i]; };
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];