Smarandache-Wellin primes: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(18 intermediate revisions by 10 users not shown)
Line 1:
{{draft task}}
;Definitions
A '''Smarandache-Wellin number''' (S-W number for short) is an integer that in a given base is the concatenation of the first n prime numbers written in that base. A base of 10 will be assumed for this task.
Line 162:
19th: index 1087 prime 208614364610327343341589284471
20th: index 1188 prime 229667386663354357356628334581
</pre>
 
=={{header|C++}}==
{{libheader|GMP}}
{{libheader|Primesieve}}
<syntaxhighlight lang="cpp">#include <iomanip>
#include <iostream>
#include <string>
 
#include <primesieve.hpp>
 
#include <gmpxx.h>
 
using big_int = mpz_class;
 
class sw_number_generator {
public:
sw_number_generator() { next(); }
void next();
const std::string& number() const { return number_; }
uint64_t prime() const { return prime_; }
int index() const { return index_; }
std::string derived_number() const;
 
private:
primesieve::iterator pi_;
std::string number_;
uint64_t prime_;
int index_ = 0;
};
 
void sw_number_generator::next() {
++index_;
prime_ = pi_.next_prime();
number_ += std::to_string(prime_);
}
 
std::string sw_number_generator::derived_number() const {
int count[10] = {};
for (char c : number_)
++count[c - '0'];
std::string str;
for (int i = 0; i < 10; ++i) {
if (!str.empty() || count[i] != 0)
str += std::to_string(count[i]);
}
return str;
}
 
bool is_probably_prime(const big_int& n) {
return mpz_probab_prime_p(n.get_mpz_t(), 25) != 0;
}
 
std::string abbreviate(std::string str, size_t max_digits) {
size_t len = str.size();
if (len > max_digits)
str.replace(max_digits / 2, len - max_digits, "...");
return str;
}
 
void print_sw_primes() {
std::cout
<< "Known Smarandache-Wellin primes:\n\n"
<< " |Index|Digits|Last prime| Smarandache-Wellin prime\n"
<< "----------------------------------------------------------------------\n";
sw_number_generator swg;
for (int n = 1; n <= 8; swg.next()) {
std::string num = swg.number();
if (is_probably_prime(big_int(num))) {
std::cout << std::setw(2) << n << "|"
<< std::setw(5) << swg.index() << "|"
<< std::setw(6) << num.size() << "|"
<< std::setw(10) << swg.prime() << "|"
<< std::setw(43) << abbreviate(num, 40) << '\n';
++n;
}
}
}
 
void print_derived_sw_primes(int count) {
std::cout << "First " << count << " Derived Smarandache-Wellin primes:\n\n"
<< " |Index|Derived Smarandache-Wellin prime\n"
<< "-----------------------------------------\n";
sw_number_generator swg;
for (int n = 1; n <= count; swg.next()) {
std::string num = swg.derived_number();
if (is_probably_prime(big_int(num))) {
std::cout << std::setw(2) << n << "|"
<< std::setw(5) << swg.index() << "|"
<< std::setw(32) << num << '\n';
++n;
}
}
}
 
int main() {
print_sw_primes();
std::cout << '\n';
print_derived_sw_primes(20);
}</syntaxhighlight>
 
{{out}}
<pre>
Known Smarandache-Wellin primes:
 
|Index|Digits|Last prime| Smarandache-Wellin prime
----------------------------------------------------------------------
1| 1| 1| 2| 2
2| 2| 2| 3| 23
3| 4| 4| 7| 2357
4| 128| 355| 719|23571113171923293137...73677683691701709719
5| 174| 499| 1033|23571113171923293137...10131019102110311033
6| 342| 1171| 2297|23571113171923293137...22732281228722932297
7| 435| 1543| 3037|23571113171923293137...30013011301930233037
8| 1429| 5719| 11927|23571113171923293137...11903119091192311927
 
First 20 Derived Smarandache-Wellin primes:
 
|Index|Derived Smarandache-Wellin prime
-----------------------------------------
1| 32| 4194123321127
2| 72| 547233879626521
3| 73| 547233979727521
4| 134| 13672766322929571043
5| 225| 3916856106393739943689
6| 303| 462696313560586013558131
7| 309| 532727113760586013758133
8| 363| 6430314317473636515467149
9| 462| 8734722823685889120488197
10| 490| 9035923128899919621189209
11| 495| 9036023329699969621389211
12| 522| 9337023533410210710923191219
13| 538| 94374237357103109113243102223
14| 624| 117416265406198131121272110263
15| 721| 141459282456260193137317129313
16| 738| 144466284461264224139325131317
17| 790| 156483290479273277162351153339
18| 852| 164518312512286294233375158359
19| 1087| 208614364610327343341589284471
20| 1188| 229667386663354357356628334581
</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
func nextprim num .
while isprim num = 0
num += 1
.
return num
.
len digs[] 10
prim = 1
while len prsw[] < 3 or len prdsw[] < 3
prim = nextprim (prim + 1)
h = prim
h[] = [ ]
while h > 0
d = h mod 10
digs[d + 1] += 1
h[] &= d
h = h div 10
.
for i = len h[] downto 1
sw = sw * 10 + h[i]
.
if isprim sw = 1
prsw[] &= sw
.
dsw = 0
for i to 10
if digs[i] = 0
h = 10
else
h = 1 + floor log10 digs[i]
h = pow 10 h
.
dsw = dsw * h + digs[i]
.
if isprim dsw = 1
prdsw[] &= dsw
.
.
print prsw[]
print prdsw[]
</syntaxhighlight>
 
{{out}}
<pre>
[ 2 23 2357 ]
[ 4194123321127 547233879626521 547233979727521 ]
</pre>
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// Smarandache-Wellin primes. Nigel Galloway: April 3rd., 2023
let izP(g,_,_,_)=let mutable g=System.Numerics.BigInteger.Parse g
Open.Numeric.Primes.MillerRabin.IsProbablePrime &g
let fN g="0123456789"+g|>Seq.countBy id|>Seq.map(fun(_,g)->string(g-1))|>Seq.fold((+))""
let sw()=primes32()|>Seq.scan(fun(n,i,g,e)l->let a=string l in (n+a,l,g+1,e+(String.length a)))("",0,0,0)|>Seq.skip 1
sw()|>Seq.filter izP|>Seq.take 3|>Seq.iter(fun(i,_,_,_)->printf "%s " i); printfn ""
sw()|>Seq.filter izP|>Seq.take 7|>Seq.iter(fun(_,n,g,l)->printfn "index %4d: digits %4d last prime %d" g l n); printfn ""
sw()|>Seq.map(fun(i,g,e,l)->(fN i,g,e,l))|>Seq.filter izP|>Seq.take 20|>Seq.iter(fun(n,_,g,_)->printfn $"index %4d{g}: prime %s{n}")
</syntaxhighlight>
{{out}}
<pre>
2 23 2357
index 1: digits 1 last prime 2
index 2: digits 2 last prime 3
index 4: digits 4 last prime 7
index 128: digits 355 last prime 719
index 174: digits 499 last prime 1033
index 342: digits 1171 last prime 2297
index 435: digits 1543 last prime 3037
index 32: prime 4194123321127
index 72: prime 547233879626521
index 73: prime 547233979727521
index 134: prime 13672766322929571043
index 225: prime 3916856106393739943689
index 303: prime 462696313560586013558131
index 309: prime 532727113760586013758133
index 363: prime 6430314317473636515467149
index 462: prime 8734722823685889120488197
index 490: prime 9035923128899919621189209
index 495: prime 9036023329699969621389211
index 522: prime 9337023533410210710923191219
index 538: prime 94374237357103109113243102223
index 624: prime 117416265406198131121272110263
index 721: prime 141459282456260193137317129313
index 738: prime 144466284461264224139325131317
index 790: prime 156483290479273277162351153339
index 852: prime 164518312512286294233375158359
index 1087: prime 208614364610327343341589284471
index 1188: prime 229667386663354357356628334581
</pre>
 
Line 271 ⟶ 514:
19th: index 1087 prime 208614364610327343341589284471
20th: index 1188 prime 229667386663354357356628334581
</pre>
 
=={{header|J}}==
<syntaxhighlight lang="j"> derive=. [: <:@#/.~ i.@10 , ]
digits=. ;@:(<@("."0@":)"0)
(#~ 1&p:) 10&#.@digits\ p: i. 10
2 23 2357
 
(#~ 1 p: {:"1) (# , 10x&#.@digits@derive@digits)\ p: i. 1200
32 4194123321127
72 547233879626521
73 547233979727521
134 13672766322929571043
225 3916856106393739943689
303 462696313560586013558131
309 532727113760586013758133
363 6430314317473636515467149
462 8734722823685889120488197
490 9035923128899919621189209
495 9036023329699969621389211
522 9337023533410210710923191219
538 94374237357103109113243102223
624 117416265406198131121272110263
721 141459282456260193137317129313
738 144466284461264224139325131317
790 156483290479273277162351153339
852 164518312512286294233375158359
1087 208614364610327343341589284471
1188 229667386663354357356628334581</syntaxhighlight>
 
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
public final class SmarandacheWellinPrimes {
 
public static void main(String[] args) {
primes = listPrimesUpTo(12_000);
smarandacheWellinPrimes();
System.out.println();
derivedSmarandacheWellinPrimes();
}
private static void smarandacheWellinPrimes() {
int count = 0;
int index = 1;
int number = 2;
String numberString = "2";
System.out.println("The first eight Smarandache-Wellin primes are:");
while ( count < 8 ) {
if ( new BigInteger(numberString).isProbablePrime(CERTAINTY_LEVEL) ) {
count += 1;
System.out.println(String.format("%2d%s%-4d%s%-5d%s%d", count, ": index = ", index,
" last prime = ", number, " number of digits = ", numberString.length()));
}
number = primes.get(index);
numberString += number;
index += 1;
}
}
private static void derivedSmarandacheWellinPrimes() {
int count = 0;
int index = 0;
int[] digitFrequencies = new int[10];
System.out.println("The first 20 derived Smarandache-Wellin numbers which are prime:");
while ( count < 20 ) {
String prime = String.valueOf(primes.get(index));
for ( char ch : prime.toCharArray() ) {
digitFrequencies[ch - '0'] += 1;
}
index += 1;
String joined = Arrays.stream(digitFrequencies).mapToObj(String::valueOf).collect(Collectors.joining(""));
if ( new BigInteger(joined).isProbablePrime(CERTAINTY_LEVEL) ) {
count += 1;
System.out.println(String.format("%2d%s%-4d%s%s", count, ": index = ", index, " prime = ", joined));
}
}
}
private static List<Integer> listPrimesUpTo(int limit) {
final int halfLimit = ( limit + 1 ) / 2;
boolean[] composite = new boolean[halfLimit];
for ( int i = 1, p = 3; i < halfLimit; p += 2, i++ ) {
if ( ! composite[i] ) {
for ( int a = i + p; a < halfLimit; a += p ) {
composite[a] = true;
}
}
}
List<Integer> result = Stream.of(2).limit(1).collect(Collectors.toList());
for ( int i = 1, p = 3; i < halfLimit; p += 2, i++ ) {
if ( ! composite[i] ) {
result.add(p);
}
}
return result;
}
private static List<Integer> primes;
private static final int CERTAINTY_LEVEL = 15;
}
</syntaxhighlight>
{{ out }}
<pre>
The first eight Smarandache-Wellin primes are:
1: index = 1 last prime = 2 number of digits = 1
2: index = 2 last prime = 3 number of digits = 2
3: index = 4 last prime = 7 number of digits = 4
4: index = 128 last prime = 719 number of digits = 355
5: index = 174 last prime = 1033 number of digits = 499
6: index = 342 last prime = 2297 number of digits = 1171
7: index = 435 last prime = 3037 number of digits = 1543
8: index = 1429 last prime = 11927 number of digits = 5719
 
The first 20 derived Smarandache-Wellin numbers which are prime:
1: index = 32 prime = 4194123321127
2: index = 72 prime = 547233879626521
3: index = 73 prime = 547233979727521
4: index = 134 prime = 13672766322929571043
5: index = 225 prime = 3916856106393739943689
6: index = 303 prime = 462696313560586013558131
7: index = 309 prime = 532727113760586013758133
8: index = 363 prime = 6430314317473636515467149
9: index = 462 prime = 8734722823685889120488197
10: index = 490 prime = 9035923128899919621189209
11: index = 495 prime = 9036023329699969621389211
12: index = 522 prime = 9337023533410210710923191219
13: index = 538 prime = 94374237357103109113243102223
14: index = 624 prime = 117416265406198131121272110263
15: index = 721 prime = 141459282456260193137317129313
16: index = 738 prime = 144466284461264224139325131317
17: index = 790 prime = 156483290479273277162351153339
18: index = 852 prime = 164518312512286294233375158359
19: index = 1087 prime = 208614364610327343341589284471
20: index = 1188 prime = 229667386663354357356628334581
</pre>
 
Line 317 ⟶ 708:
SmarandacheWellin()
</syntaxhighlight>{{out}} Same as C and Go versions.
 
=={{header|Nim}}==
{{libheader|Nim-Integers}}
<syntaxhighlight lang="Nim">import std/[bitops, math, strformat, strutils, sugar, tables]
 
import integers
 
const N = 12_000
let primes = @[2] & collect(for n in countup(3, N, 2):
if n.isPrime: n)
 
func compressed(str: string; size: int): string =
## Return a compressed value for long strings of digits.
if str.len <= 2 * size: str
else: &"{str[0..<size]}...{str[^size..^1]} ({str.len} digits)"
 
iterator swNumbers(): tuple[value: Integer; lastPrime: int] =
## Yield the SW-Numbers and the last prime added.
var swString = ""
for p in primes:
swString.addInt p
yield (newInteger(swString), p)
 
iterator derivedSwNumbers(): Integer =
## Yield the derived SW-Numbers.
for (n, _) in swNumbers():
var dSwString = ""
let counts = toCountTable($n)
for d in '0'..'9':
dSwString.add $counts[d]
yield newInteger(dSwString.strip(leading = true, trailing = false, {'0'}))
 
echo "Known eight Smarandache-Wellin numbers which are prime:"
var idx, count = 0
for (n, p)in swNumbers():
inc idx
if n.isPrime:
inc count
echo &"{count}: index = {idx:<4} last prime = {p:<5} value = {compressed($n, 20)}"
if count == 8: break
 
echo "\nFirst 20 derived S-W numbers which are prime:"
idx = 0
count = 0
for n in derivedSwNumbers():
inc idx
if n.isPrime:
inc count
echo &"{count:2}: index = {idx:<4} value = {n}"
if count == 20: break
</syntaxhighlight>
 
{{out}}
<pre>Known eight Smarandache-Wellin numbers which are prime:
1: index = 1 last prime = 2 value = 2
2: index = 2 last prime = 3 value = 23
3: index = 4 last prime = 7 value = 2357
4: index = 128 last prime = 719 value = 23571113171923293137...73677683691701709719 (355 digits)
5: index = 174 last prime = 1033 value = 23571113171923293137...10131019102110311033 (499 digits)
6: index = 342 last prime = 2297 value = 23571113171923293137...22732281228722932297 (1171 digits)
7: index = 435 last prime = 3037 value = 23571113171923293137...30013011301930233037 (1543 digits)
8: index = 1429 last prime = 11927 value = 23571113171923293137...11903119091192311927 (5719 digits)
 
First 20 derived S-W numbers which are prime:
1: index = 32 value = 4194123321127
2: index = 72 value = 547233879626521
3: index = 73 value = 547233979727521
4: index = 134 value = 13672766322929571043
5: index = 225 value = 3916856106393739943689
6: index = 303 value = 462696313560586013558131
7: index = 309 value = 532727113760586013758133
8: index = 363 value = 6430314317473636515467149
9: index = 462 value = 8734722823685889120488197
10: index = 490 value = 9035923128899919621189209
11: index = 495 value = 9036023329699969621389211
12: index = 522 value = 9337023533410210710923191219
13: index = 538 value = 94374237357103109113243102223
14: index = 624 value = 117416265406198131121272110263
15: index = 721 value = 141459282456260193137317129313
16: index = 738 value = 144466284461264224139325131317
17: index = 790 value = 156483290479273277162351153339
18: index = 852 value = 164518312512286294233375158359
19: index = 1087 value = 208614364610327343341589284471
20: index = 1188 value = 229667386663354357356628334581
</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<syntaxhighlight lang="perl" line>
use v5.36;
use ntheory <is_prime next_prime>;
use Lingua::EN::Numbers::Ordinate 'ordinate';
 
sub abbr ($d) { my $l = length $d; $l < 41 ? $d : substr($d,0,20) . '..' . substr($d,-20) . " ($l digits)" }
 
print "Smarandache-Wellen primes:\n";
my($p, $i, $nth, $n) = (0, -1, 0);
do {
$p = next_prime($p);
$n .= $p;
$i++;
(++$nth and printf("%s: Index:%5d Last prime:%6d S-W: %s\n", ordinate $nth, $i, $p, abbr $n)) if is_prime $n;
} until $nth == 8;
 
sub derived ($n) {
my %digits;
$digits{$_}++ for split '', $n;
join '', map { $digits{$_} // 0 } 0..9;
}
 
print "\nSmarandache-Wellen derived primes:\n";
($p, $i, $nth, $n) = (1, -1, 0, '');
do {
$i++;
$n .= ($p = next_prime($p));
++$nth and printf "%4s: Index:%5d %s\n", ordinate $nth, $i, derived $n if is_prime derived $n;
} until $nth == 20;
</syntaxhighlight>
{{out}}
<pre>
Smarandache-Wellen primes:
1st: Index: 0 Last prime: 2 S-W: 2
2nd: Index: 1 Last prime: 3 S-W: 23
3rd: Index: 3 Last prime: 7 S-W: 2357
4th: Index: 127 Last prime: 719 S-W: 23571113171923293137..73677683691701709719 (355 digits)
5th: Index: 173 Last prime: 1033 S-W: 23571113171923293137..10131019102110311033 (499 digits)
6th: Index: 341 Last prime: 2297 S-W: 23571113171923293137..22732281228722932297 (1171 digits)
7th: Index: 434 Last prime: 3037 S-W: 23571113171923293137..30013011301930233037 (1543 digits)
8th: Index: 1428 Last prime: 11927 S-W: 23571113171923293137..11903119091192311927 (5719 digits)
 
Smarandache-Wellen derived primes:
1st: Index: 31 4194123321127
2nd: Index: 71 547233879626521
3rd: Index: 72 547233979727521
4th: Index: 133 13672766322929571043
5th: Index: 224 3916856106393739943689
6th: Index: 302 462696313560586013558131
7th: Index: 308 532727113760586013758133
8th: Index: 362 6430314317473636515467149
9th: Index: 461 8734722823685889120488197
10th: Index: 489 9035923128899919621189209
11th: Index: 494 9036023329699969621389211
12th: Index: 521 9337023533410210710923191219
13th: Index: 537 94374237357103109113243102223
14th: Index: 623 117416265406198131121272110263
15th: Index: 720 141459282456260193137317129313
16th: Index: 737 144466284461264224139325131317
17th: Index: 789 156483290479273277162351153339
18th: Index: 851 164518312512286294233375158359
19th: Index: 1086 208614364610327343341589284471
20th: Index: 1187 229667386663354357356628334581
</pre>
 
=={{header|Phix}}==
Line 353 ⟶ 896:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Smarandache-WhellenWellin primes:\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span> <span style="color: #008080;">in</span> <span style="color: #000000;">swp</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" %d%s:"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">ord</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" Index: %4d, Last prime %5d, %s\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Smarandache-WhellenWellin derived primes:\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span> <span style="color: #008080;">in</span> <span style="color: #000000;">swdp</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" %d%s:"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">ord</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)})</span>
Line 367 ⟶ 910:
{{out}}
<pre>
Smarandache-WhellenWellin primes:
1st: Index: 1, Last prime 2, 2
2nd: Index: 2, Last prime 3, 23
Line 376 ⟶ 919:
7th: Index: 435, Last prime 3037, 23571113171923293137...30013011301930233037 (1,543 digits)
8th: Index: 1429, Last prime 11927, 23571113171923293137...11903119091192311927 (5,719 digits)
Smarandache-WhellenWellin derived primes:
1st: Index: 32, 4194123321127
2nd: Index: 72, 547233879626521
Line 406 ⟶ 949:
my @primes = (^∞).grep: &is-prime;
 
my @Smarandache-WhellenWellin = [\~] @primes;
 
sink @Smarandache-WhellenWellin[1500]; # pre-reify for concurrency
 
sub derived ($n) { my %digits = $n.comb.Bag; (0..9).map({ %digits{$_} // 0 }).join }
Line 414 ⟶ 957:
sub abbr ($_) { .chars < 41 ?? $_ !! .substr(0,20) ~ '…' ~ .substr(*-20) ~ " ({.chars} digits)" }
 
say "Smarandache-WhellenWellin primes:";
say ordinal-digit(++$,:u).fmt("%4s") ~ $_ for (^∞).hyper(:4batch).map({
next unless (my $sw = @Smarandache-WhellenWellin[$_]).is-prime;
sprintf ": Index: %4d, Last prime: %5d, %s", $_, @primes[$_], $sw.&abbr
})[^8];
 
say "\nSmarandache-WhellenWellin derived primes:";
say ordinal-digit(++$,:u).fmt("%4s") ~ $_ for (^∞).hyper(:8batch).map({
next unless (my $sw = @Smarandache-WhellenWellin[$_].&derived).is-prime;
sprintf ": Index: %4d, %s", $_, $sw
})[^20];</syntaxhighlight>
{{out}}
<pre>Smarandache-WhellenWellin primes:
1ˢᵗ: Index: 0, Last prime: 2, 2
2ⁿᵈ: Index: 1, Last prime: 3, 23
Line 436 ⟶ 979:
8ᵗʰ: Index: 1428, Last prime: 11927, 23571113171923293137…11903119091192311927 (5719 digits)
 
Smarandache-WhellenWellin derived primes:
1ˢᵗ: Index: 31, 4194123321127
2ⁿᵈ: Index: 71, 547233879626521
Line 457 ⟶ 1,000:
19ᵗʰ: Index: 1086, 208614364610327343341589284471
20ᵗʰ: Index: 1187, 229667386663354357356628334581</pre>
 
=={{header|RPL}}==
The latest versions of RPL can handle large 500-digit integers, making it possible to search for the fifth SW prime. Unfortunately, even with an emulator, the primality test takes too long.
{{works with|HP|49}}
« "" 2
1 4 ROLL '''FOR''' j
SWAP OVER + SWAP NEXTPRIME
'''NEXT''' DROP
» » '<span style="color:blue">→SW</span>' STO
« →STR → swn
« { 10 } 0 CON
1 swn SIZE '''FOR''' j
swn j DUP SUB STR→ 1 + DUP2 GET 1 + PUT
'''NEXT'''
""
1 10 '''FOR''' j
OVER j GET +
'''NEXT'''
STR→ NIP
» '<span style="color:blue">DSW</span>' STO
« 0 → idx
« { }
'''WHILE''' DUP SIZE 4 < '''REPEAT'''
'''IF''' 'idx' INCR <span style="color:blue">→SW</span> DUP ISPRIME? '''THEN''' + '''ELSE''' DROP '''END'''
'''END'''
» » '<span style="color:blue">TASK1</span>' STO
« 0 → idx
« { }
'''WHILE''' DUP SIZE 4 < '''REPEAT'''
'''IF''' 'idx' INCR <span style="color:blue">→SW DSW</span> DUP ISPRIME? '''THEN''' + '''ELSE''' DROP '''END'''
'''END'''
» » '<span style="color:blue">TASK2</span>' STO
{{out}}
<pre>
2: { 2 23 2357 2357111317192329313741434753596167717379838997101103107109113127131137139149151157163167173179181191193197199211223227229233239241251257263269271277281283293307311313317331337347349353359367373379383389397401409419421431433439443449457461463467479487491499503509521523541547557563569571577587593599601607613617619631641643647653659661673677683691701709719 }
1: { 4194123321127 547233879626521 547233979727521 13672766322929571043 }
</pre>
 
=={{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.
Line 564 ⟶ 1,148:
{{libheader|Wren-gmp}}
Need to use GMP here to find the 8th S-W prime in a reasonable time (35.5 seconds on my Core i7 machine).
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./gmp" for Mpz
import "./fmt"for Fmt
9,476

edits