Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List returned by .row has properties different from lists returned by other methods #68

Open
tsalada opened this issue Jul 9, 2021 · 0 comments

Comments

@tsalada
Copy link

tsalada commented Jul 9, 2021

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";
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant