Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Fusc-sequence/Perl/fusc-sequence.pl
Normal file
25
Task/Fusc-sequence/Perl/fusc-sequence.pl
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use feature 'say';
|
||||
|
||||
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }
|
||||
|
||||
sub stern_diatomic {
|
||||
my ($p,$q,$i) = (0,1,shift);
|
||||
while ($i) {
|
||||
if ($i & 1) { $p += $q; } else { $q += $p; }
|
||||
$i >>= 1;
|
||||
}
|
||||
$p;
|
||||
}
|
||||
|
||||
say "First 61 terms of the Fusc sequence:\n" . join ' ', map { stern_diatomic($_) } 0..60;
|
||||
say "\nIndex and value for first term longer than any previous:";
|
||||
|
||||
my $i = 0;
|
||||
my $l = -1;
|
||||
while ($l < 5) {
|
||||
my $v = stern_diatomic($i);
|
||||
printf("%15s : %s\n", comma($i), comma($v)) and $l = length $v if length $v > $l;
|
||||
$i++;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue