Numbers which are not the sum of distinct squares: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
SqrtNegInf (talk | contribs) (Added Perl) |
||
Line 426: | Line 426: | ||
2,3,6,7,8,11,12,15,18,19,22,23,24,27,28,31,32,33,43,44,47,48,60,67,72,76,92,96,108,112,128, |
2,3,6,7,8,11,12,15,18,19,22,23,24,27,28,31,32,33,43,44,47,48,60,67,72,76,92,96,108,112,128, |
||
</pre> |
</pre> |
||
=={{header|Perl}}== |
|||
{{trans|Raku}} |
|||
<syntaxhighlight lang="perl" line>use v5.36; |
|||
use List::Util <sum uniq none>; |
|||
use Algorithm::Combinatorics 'combinations'; |
|||
my @squares = map { $_**2 } 0..100; |
|||
my $sq; |
|||
while (++$sq) { |
|||
my(@sums, @run); |
|||
for (1..$sq) { |
|||
push @sums, sum @squares[@$_] for combinations [1..$sq+1], $_ |
|||
} |
|||
@sums = uniq sort { $a <=> $b } @sums; |
|||
for (@sums) { |
|||
push(@run, $_) and next unless @run; |
|||
if ($_ == $run[-1] + 1) { push @run, $_ } else { last if @run > $squares[$sq]; @run = () } |
|||
} |
|||
next unless @run; |
|||
for my $i (1..$run[-1]) { |
|||
push @res, $i if none { $i eq $_ } @sums |
|||
} |
|||
last if @run > $squares[$sq]; |
|||
}</syntaxhighlight> |
|||
{{out}} |
|||
<pre>2 3 6 7 8 11 12 15 18 19 22 23 24 27 28 31 32 33 43 44 47 48 60 67 72 76 92 96 108 112 128</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |