Increasing gaps between consecutive Niven numbers: Difference between revisions
Content added Content deleted
(added header pascal) |
SqrtNegInf (talk | contribs) (Added Perl example) |
||
Line 359: | Line 359: | ||
real 2m37,350s |
real 2m37,350s |
||
</pre> |
</pre> |
||
=={{header|Perl}}== |
|||
{{trans|Perl 6}} |
|||
<lang perl>use strict; |
|||
use warnings; |
|||
use List::Util 'sum'; |
|||
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r } |
|||
my ($index, $last, $gap, $count) = (0, 0, 0, 0); |
|||
my $threshold = 10_000_000; |
|||
print "Gap Index of gap Starting Niven\n"; |
|||
while (1) { |
|||
$count++; |
|||
next unless 0 == $count % sum split //, $count; |
|||
if ((my $diff = $count - $last) > $gap) { |
|||
$gap = $diff; |
|||
printf "%3d %15s %15s\n", $gap, $index > 1 ? comma $index : 1, $last > 1 ? comma $last : 1; |
|||
} |
|||
$last = $count; |
|||
last if ++$index >= $threshold; |
|||
}</lang> |
|||
{{out}} |
|||
<pre>Gap Index of gap Starting Niven |
|||
1 1 1 |
|||
2 10 10 |
|||
6 11 12 |
|||
7 26 63 |
|||
8 28 72 |
|||
10 32 90 |
|||
12 83 288 |
|||
14 102 378 |
|||
18 143 558 |
|||
23 561 2,889 |
|||
32 716 3,784 |
|||
36 1,118 6,480 |
|||
44 2,948 19,872 |
|||
45 4,194 28,971 |
|||
54 5,439 38,772 |
|||
60 33,494 297,864 |
|||
66 51,544 478,764 |
|||
72 61,588 589,860 |
|||
88 94,748 989,867 |
|||
90 265,336 2,879,865 |
|||
99 800,054 9,898,956 |
|||
108 3,750,017 49,989,744 |
|||
126 6,292,149 88,996,914</pre> |
|||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{works with|Rakudo|2019.11}} |
{{works with|Rakudo|2019.11}} |