Smarandache-Wellin primes: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(→‎J: faster digit retrieval)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(5 intermediate revisions by 3 users not shown)
Line 215:
}
 
std::string abbreviate(const std::string& str, size_t nmax_digits) {
size_t len = str.size();
if (len > nmax_digits)
return str.substrreplace(0, nmax_digits / 2), +len - max_digits, "..." + str.substr(len - n / 2);
return str;
}
Line 302:
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>
 
Line 940 ⟶ 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}}==
Line 1,048 ⟶ 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