Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions

→‎{{header|Perl 6}}: various tweaks, expand last sequence to 15 terms
(→‎{{header|Perl 6}}: various tweaks, expand last sequence to 15 terms)
Line 383:
This task could be interpreted in a few ways.
 
Could be the sequence of the '''smallest natural numbers''' such that each <strong>a<sub>n</sub></strong> has '''n''' divisors: [[oeis:A005179|OEIS: A005179]].
 
Or, could be the sequence where each term <strong>a<sub>n</sub></strong> is the <strong>smallest natural number &gt; a<sub>n-1</sub></strong> that has '''n''' divisors: [[oeis:A069654|OEIS: A069654]].
 
Or, it could be something else entirely.
Line 398:
}
 
my $limit = 15;
put 'First 15 terms of OEIS: A005179';
 
put (1..15).map: -> $n { first { $n == .&div-count }, 1..Inf };
put '"First 15$limit terms of OEIS: A005179'";
put (1..15$limit).map: -> $n { first { $n == .&div-count }, 1..Inf };
 
my $m = 1;
put "\nFirst 15$limit terms of OEIS: A069654";
put (1..15$limit).map: -> $n { my $r = $m = first { $n == .&div-count }, $m..Inf };
 
# Actually, since there is no verbiage in the task description about
# choosing the _smallest_ integer, for each term, this complies with
# a strict interpretation of the requirements.
 
put "\nTechnically correct is the best kind of correct:";
my $antipp = (1..5000).race.classify: { .&div-count };
put "\nTechnically correct is the best kind of correct:";
put (1..15$limit).map: { $antipp{$_}.pick };
 
# Oooo! Here's a good one. Each term is the nth occurrence of an integer with
# n divisors. Limit to 10 terms as this gets pretty intensive pretty quickly.
 
my @primes = grep { .is-prime }, 1..*;
@primes[$limit]; # prime the array. SCNR
 
put "\nNth occurrence of an integer with n divisors:";
put (1..10$limit).hyper(:1batch2batch).map: -> $n {
my ($in => 4 and $n.is-prime) 0;??
my exp($iteratorn =- 1, @primes[$n %%- 2 ?? (1..*]) !! (1..*).map: *²;
$iterator.first:do {
next unlessmy $ni == .&div-count0;
next(1..*).first: unless ++$i == $n;{
next unless $_n == .&div-count;
next unless ++$i == $n;
$_
}
}
};</lang>
{{out}}
<pre>First 15 terms of OEIS: A005179
1 2 4 6 16 12 64 24 36 48 1024 60 4096 192 144
 
First 15 terms of OEIS: A069654
1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624
 
Technically correct is the best kind of correct:
1 21371777 499 989 2401625 29084527 72964 7831270 30251444 43754208 1024 35961694 4096 23683776 2500144
 
Nth occurrence of an integer with n divisors:
1 3 25 14 14641 44 24137569 70 1089 405 819628286980801 160 22563490300366186081 2752 9801</pre>
 
=={{header|REXX}}==
10,333

edits