Smarandache-Wellin primes: Difference between revisions
Content added Content deleted
m (→Basic: Removed a superfluous line.) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: Add a Raku example) |
||
Line 30: | Line 30: | ||
<br> |
<br> |
||
=={{header|Raku}}== |
|||
The first seven Smarandache-Wellin primes are found in a few seconds on my system. The eighth adds over five minutes to the run time. |
|||
<syntaxhighlight lang="raku" line>my @primes = (^∞).grep: &is-prime; |
|||
my @Smarandache-Whellen = [\~] @primes; |
|||
sink @Smarandache-Whellen[1500]; # pre-reify for concurrency |
|||
sub derived ($n) { my %digits = $n.comb.Bag; (1..9).map({ %digits{$_} // 0 }).join } |
|||
sub abbr ($_) { .chars < 41 ?? $_ !! .substr(0,20) ~ '…' ~ .substr(*-20) ~ " ({.chars} digits)" } |
|||
say "Smarandache-Whellen primes:\n " ~ |
|||
(^∞).hyper(:4batch).map({ |
|||
next unless (my $sw = @Smarandache-Whellen[$_]).is-prime; |
|||
sprintf " Index: %4d, Last prime: %5d, %s\n", $_, @primes[$_], $sw.&abbr |
|||
})[^8]; |
|||
say "\nSmarandache-Whellen derived primes:\n " ~ |
|||
(^∞).hyper(:8batch).map({ |
|||
next unless (my $sw = @Smarandache-Whellen[$_].&derived).is-prime; |
|||
sprintf " Index: %4d, %s\n", $_, $sw |
|||
})[^10];</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Smarandache-Whellen primes: |
|||
Index: 0, Last prime: 2, 2 |
|||
Index: 1, Last prime: 3, 23 |
|||
Index: 3, Last prime: 7, 2357 |
|||
Index: 127, Last prime: 719, 23571113171923293137…73677683691701709719 (355 digits) |
|||
Index: 173, Last prime: 1033, 23571113171923293137…10131019102110311033 (499 digits) |
|||
Index: 341, Last prime: 2297, 23571113171923293137…22732281228722932297 (1171 digits) |
|||
Index: 434, Last prime: 3037, 23571113171923293137…30013011301930233037 (1543 digits) |
|||
Index: 1428, Last prime: 11927, 23571113171923293137…11903119091192311927 (5719 digits) |
|||
Smarandache-Whellen derived primes: |
|||
Index: 64, 45232857623519 |
|||
Index: 73, 47234179728521 |
|||
Index: 101, 55265428181036833 |
|||
Index: 108, 56265628251240937 |
|||
Index: 110, 57265628251441937 |
|||
Index: 112, 59265728251642937 |
|||
Index: 122, 63266131272746939 |
|||
Index: 153, 723172323232702949 |
|||
Index: 208, 1465092363737883583 |
|||
Index: 230, 17557110463939953691 |
|||
</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |