Smarandache-Wellin primes: Difference between revisions
Content added Content deleted
(Realize in F#) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: Fix typos) |
||
Line 448: | Line 448: | ||
my @primes = (^∞).grep: &is-prime; |
my @primes = (^∞).grep: &is-prime; |
||
my @Smarandache- |
my @Smarandache-Wellen = [\~] @primes; |
||
sink @Smarandache- |
sink @Smarandache-Wellen[1500]; # pre-reify for concurrency |
||
sub derived ($n) { my %digits = $n.comb.Bag; (0..9).map({ %digits{$_} // 0 }).join } |
sub derived ($n) { my %digits = $n.comb.Bag; (0..9).map({ %digits{$_} // 0 }).join } |
||
Line 456: | Line 456: | ||
sub abbr ($_) { .chars < 41 ?? $_ !! .substr(0,20) ~ '…' ~ .substr(*-20) ~ " ({.chars} digits)" } |
sub abbr ($_) { .chars < 41 ?? $_ !! .substr(0,20) ~ '…' ~ .substr(*-20) ~ " ({.chars} digits)" } |
||
say "Smarandache- |
say "Smarandache-Wellen primes:"; |
||
say ordinal-digit(++$,:u).fmt("%4s") ~ $_ for (^∞).hyper(:4batch).map({ |
say ordinal-digit(++$,:u).fmt("%4s") ~ $_ for (^∞).hyper(:4batch).map({ |
||
next unless (my $sw = @Smarandache- |
next unless (my $sw = @Smarandache-Wellen[$_]).is-prime; |
||
sprintf ": Index: %4d, Last prime: %5d, %s", $_, @primes[$_], $sw.&abbr |
sprintf ": Index: %4d, Last prime: %5d, %s", $_, @primes[$_], $sw.&abbr |
||
})[^8]; |
})[^8]; |
||
say "\nSmarandache- |
say "\nSmarandache-Wellen derived primes:"; |
||
say ordinal-digit(++$,:u).fmt("%4s") ~ $_ for (^∞).hyper(:8batch).map({ |
say ordinal-digit(++$,:u).fmt("%4s") ~ $_ for (^∞).hyper(:8batch).map({ |
||
next unless (my $sw = @Smarandache- |
next unless (my $sw = @Smarandache-Wellen[$_].&derived).is-prime; |
||
sprintf ": Index: %4d, %s", $_, $sw |
sprintf ": Index: %4d, %s", $_, $sw |
||
})[^20];</syntaxhighlight> |
})[^20];</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Smarandache- |
<pre>Smarandache-Wellen primes: |
||
1ˢᵗ: Index: 0, Last prime: 2, 2 |
1ˢᵗ: Index: 0, Last prime: 2, 2 |
||
2ⁿᵈ: Index: 1, Last prime: 3, 23 |
2ⁿᵈ: Index: 1, Last prime: 3, 23 |
||
Line 478: | Line 478: | ||
8ᵗʰ: Index: 1428, Last prime: 11927, 23571113171923293137…11903119091192311927 (5719 digits) |
8ᵗʰ: Index: 1428, Last prime: 11927, 23571113171923293137…11903119091192311927 (5719 digits) |
||
Smarandache- |
Smarandache-Wellen derived primes: |
||
1ˢᵗ: Index: 31, 4194123321127 |
1ˢᵗ: Index: 31, 4194123321127 |
||
2ⁿᵈ: Index: 71, 547233879626521 |
2ⁿᵈ: Index: 71, 547233879626521 |
||
Line 499: | Line 499: | ||
19ᵗʰ: Index: 1086, 208614364610327343341589284471 |
19ᵗʰ: Index: 1086, 208614364610327343341589284471 |
||
20ᵗʰ: Index: 1187, 229667386663354357356628334581</pre> |
20ᵗʰ: Index: 1187, 229667386663354357356628334581</pre> |
||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
The first seven Smarandache-Wellin primes are found in about 12 seconds on my system. The eighth (not shown here) takes nine minutes. |
The first seven Smarandache-Wellin primes are found in about 12 seconds on my system. The eighth (not shown here) takes nine minutes. |