Factor-perfect numbers: Difference between revisions
m
→{{header|Raku}}: use 'state' variable instead of global, syntax twiddles
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: use 'state' variable instead of global, syntax twiddles) |
|||
Line 480:
<syntaxhighlight lang="raku" line># 20221029 Raku programming solution
sub propdiv (\x) {
my ($n,@fpns,%cache) = 4, 0,1;▼
my @l = 1 if x > 1;
for (2 .. x.sqrt.floor) -> \d {
Line 492 ⟶ 490:
sub moreMultiples (@toSeq, @fromSeq) {
my @oneMores = gather for @fromSeq -> \j {
take @toSeq.clone.push(j) if j > @toSeq[*-1]
}
return
for
@oneMores.append: moreMultiples @oneMores[$_], @fromSeq
}
}
sub erdosFactorCount (\n) {
state %cache;
my ($sum,@divs) = 0, |(propdiv n)[1..*];
for @divs -> \d {
unless %cache{my \t = n div d}:exists { %cache{t} = erdosFactorCount(t) }
$sum += %cache{t}
}
}
my @listing = moreMultiples [1], propdiv(48);
given @listing { $_.map: *.push: 48; $_.push: [1,48] }
say @listing.elems," sequences using first definition:";
Line 525 ⟶ 517:
my @seq = |@listing[j];
@seq.append: 48 if @seq[*-1] != 48;
take (1..^
}
say "\n{@listing2.elems} sequences using second definition:";
Line 531 ⟶ 523:
say "\nOEIS A163272:";
while (
say ~@fpns;</syntaxhighlight>
{{out}}
|