Magic squares/Raku: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Style tweaks) |
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Add a few comments) |
||
Line 21: | Line 21: | ||
multi sub gen-sq (2) { |
multi sub gen-sq (2) { # invalid |
||
note "Sorry, can not generate a 2 x 2 magic square." and exit; |
note "Sorry, can not generate a 2 x 2 magic square." and exit; |
||
} |
} |
||
multi sub gen-sq ($n where {$n % 2}) { |
multi sub gen-sq ($n where {$n % 2}) { # odd |
||
my $x = $n/2; |
my $x = $n/2; |
||
my $y = 0; |
my $y = 0; |
||
Line 31: | Line 31: | ||
} |
} |
||
multi sub gen-sq ($n where {$n %% 4}) { |
multi sub gen-sq ($n where {$n %% 4}) { # doubly even |
||
my $x = 0; |
my $x = 0; |
||
my $y = 0; |
my $y = 0; |
||
Line 46: | Line 46: | ||
} |
} |
||
multi sub gen-sq ($n where {$n %% 2 and $n % 4}) { |
multi sub gen-sq ($n where {$n %% 2 and $n % 4}) { # singly even |
||
my $h = $n div 2; |
my $h = $n div 2; |
||
gen-sq($h); |
gen-sq($h); |