You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using a Math::Matrix object to represent a 3x3 magic square (all rows, columns and diagonals sum to 15). The list returned by magicSquare.row(r) responds incorrectly to the list reduction operator, [+], returning 3 (the number of elements for rows 0..2) instead of 15. The lists returned by magicSquare.column, magicSquare.diagonal and magicSquare.skew-diagonal all respond correctly to the list reduction operator, [+].
#!/usr/bin/env raku
raku load_Magic_Square.raku
use Math::Matrix;
Load Known Magic Square
my $magicSquare = Math::Matrix.new( [[2,7,6], [9,5,1], [4,3,8]]);
say $magicSquare;
my @Row = ();
my $rowSum;
my @col = ();
my $colSum;
my $magicTotal = 15;
say "";
Verify Rows
for 0..2 -> $r { @Row = $magicSquare.row($r);
say "Row $r: " ~ @Row;
$rowSum = [+] @Row;
say "Row $r Sum: $rowSum";
if ($rowSum == $magicTotal) {
say "Verified Row $r";
}
say "";
}
say "";
Verify Columns
for 0..2 -> $c { @col = $magicSquare.column($c);
say "Col $c: " ~ @col;
$colSum = [+] @col;
say "Col $c Sum: $colSum";
if ($colSum == $magicTotal) {
say "Verified Column $c";
}
say "";
}
say "";
Verify Main Diagonal (Upper Left to Lower Right)
my @mDiagonal = $magicSquare.diagonal;
my $mDiagonalSum = [+] @mDiagonal;
if ($mDiagonalSum == $magicTotal) {
say "Verified Main Diagonal";
}
say "";
Verify Skew Diagonal (Lower Left to Upper Right)
my @sDiagonal = $magicSquare.skew-diagonal;
my $sDiagonalSum = [+] @sDiagonal;
if ($sDiagonalSum == $magicTotal) {
say "Verified Skew Diagonal";
}
The text was updated successfully, but these errors were encountered:
I'm using a Math::Matrix object to represent a 3x3 magic square (all rows, columns and diagonals sum to 15). The list returned by magicSquare.row(r) responds incorrectly to the list reduction operator, [+], returning 3 (the number of elements for rows 0..2) instead of 15. The lists returned by magicSquare.column, magicSquare.diagonal and magicSquare.skew-diagonal all respond correctly to the list reduction operator, [+].
#!/usr/bin/env raku
raku load_Magic_Square.raku
use Math::Matrix;
Load Known Magic Square
my $magicSquare = Math::Matrix.new( [[2,7,6], [9,5,1], [4,3,8]]);
say $magicSquare;
my @Row = ();
my $rowSum;
my @col = ();
my $colSum;
my $magicTotal = 15;
say "";
Verify Rows
for 0..2 -> $r {
@Row = $magicSquare.row($r);
say "Row $r: " ~ @Row;
$rowSum = [+] @Row;
say "Row $r Sum: $rowSum";
if ($rowSum == $magicTotal) {
say "Verified Row $r";
}
say "";
}
say "";
Verify Columns
for 0..2 -> $c {
@col = $magicSquare.column($c);
say "Col $c: " ~ @col;
$colSum = [+] @col;
say "Col $c Sum: $colSum";
if ($colSum == $magicTotal) {
say "Verified Column $c";
}
say "";
}
say "";
Verify Main Diagonal (Upper Left to Lower Right)
my @mDiagonal = $magicSquare.diagonal;
my $mDiagonalSum = [+] @mDiagonal;
if ($mDiagonalSum == $magicTotal) {
say "Verified Main Diagonal";
}
say "";
Verify Skew Diagonal (Lower Left to Upper Right)
my @sDiagonal = $magicSquare.skew-diagonal;
my $sDiagonalSum = [+] @sDiagonal;
if ($sDiagonalSum == $magicTotal) {
say "Verified Skew Diagonal";
}
The text was updated successfully, but these errors were encountered: