Jump to content

Idoneal numbers: Difference between revisions

Added Perl
(Added Go)
(Added Perl)
Line 537:
312 330 345 357 385 408 462 520 760 840 1320 1365 1848
2.036 ms per run</pre>
 
=={{header|Perl}}==
<syntaxhighlight lang="perl" line>use v5.36;
use enum qw(False True);
 
sub table ($c, @V) { my $t = $c * (my $w = 5); ( sprintf( ('%'.$w.'d')x@V, @V) ) =~ s/.{1,$t}\K/\n/gr }
 
sub is_idoneal ($n) {
LOOP:
for my $a (1 .. $n) {
for my $b ($a+1 .. $n) {
last if $a*$b + $a + $b > $n;
for my $c ($b+1 .. $n) {
return False if $n == (my $sum = $a*$b + $b*$c + $c*$a);
last if $sum > $n;
}
}
}
True
}
 
say table 10, grep { is_idoneal $_ } 1..1850;</syntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10
12 13 15 16 18 21 22 24 25 28
30 33 37 40 42 45 48 57 58 60
70 72 78 85 88 93 102 105 112 120
130 133 165 168 177 190 210 232 240 253
273 280 312 330 345 357 385 408 462 520
760 840 1320 1365 1848</pre>
 
=={{header|Phix}}==
2,392

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.