|
Math::MagicSquare::Generator - Magic Square Generator |
Math::MagicSquare::Generator - Magic Square Generator
use Math::MagicSquare::Generator
my $square = Math::MagicSquare::Generator->new(size => 5,
step => 3,
start=> 6);
for ($square, $square->vflip, $square->hflip) {
print $_->as_string;
print "-----\n";
}
$square->[0][0] = -15; # Break magic :)
print $square->check ? "Magic square\n" : "Just a square\n";
print '<html><body>';
print Math::MagicSquare::Generator->new->hflip->vflip->as_html;
print '</body></html>';
This module creates magic squares. A magic square is a square in which all numbers are different and the sums of all rows, all columns and the two diagonals are equal. Math::MagicSquare::Generator cannot create panmagic squares, or squares that have an even size. (A panmagic square is magic square where the ``wrapped'' diagonals are also equal.)
3 16 9 22 15 This square is the output of
20 8 21 14 2 print Math::MagicSquare::Generator->new->as_string;
7 25 13 1 19
24 12 5 18 6
11 4 17 10 23
The sums of the rows are 65.
The sums of the columns are 65.
The sums of the diagonals are 65.
size, step and start. size has to be positive, odd and
integer.
Math::MagicSquare is a module that checks if a square is magical. It
takes a list in its new method, so you'll have to dereference the
generated square:
use Math::MagicSquare;
use Math::MagicSquare::Generator;
my $square = Math::MagicSquare::Generator->new;
print Math::MagicSquare->new( @$square )->check, "\n"; # 2
Its check will always return 2 for squares generated using this
module (or 3 if it's a 1x1 square).
None yet.
Juerd <juerd@juerd.nl>
|
Math::MagicSquare::Generator - Magic Square Generator |