Combinations with repetitions/Square digit chain: Difference between revisions
Content added Content deleted
m (→{{header|Perl 6}}: minor update to working around warnings) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Possibly better work-around for uninitialized warnings) |
||
Line 301: | Line 301: | ||
my @ks = (7, 8, 11, 14, 17); |
my @ks = (7, 8, 11, 14, 17); |
||
for @ks -> $k { |
for @ks -> $k { |
||
my @sums = 1,0; |
my @sums is default(0) = 1,0; |
||
my $s; |
my $s; |
||
for (1 .. $k) -> $n { |
for (1 .. $k) -> $n { |
||
Line 309: | Line 309: | ||
$s = $j²; |
$s = $j²; |
||
if ($s > $i) { last }; |
if ($s > $i) { last }; |
||
@sums[$i-$s]:exists or @sums[$i-$s] = 0; # ugly work around |
|||
@sums[$i] += @sums[$i-$s]; |
@sums[$i] += @sums[$i-$s]; |
||
} |
} |