Smarandache-Wellin primes: Difference between revisions

Content deleted Content added
Chkas (talk | contribs)
Trizen (talk | contribs)
→‎{{header|Sidef}}: start the index from 1
(4 intermediate revisions by 3 users not shown)
Line 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,101 ⟶ 1,141:
19th: index 1087, prime 208614364610327343341589284471
20th: index 1188, prime 229667386663354357356628334581
</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">say "Smarandache-Wellen primes:"
 
for (var (p=2, i=1, n='', nth=1); nth <= 8; (p.next_prime!, ++i)) {
n += Str(p)
if (Num(n).is_prime){
var t = n
if (t.len > 50) {
t = (t.first(20) + ' ... ' + t.last(20) + " (#{t.len} digits)")
}
printf("%s: Index:%5d Last prime:%6d S-W: %s\n", nth, i, p, t)
++nth
}
}
 
say "\nSmarandache-Wellen derived primes:"
 
func derived(String n) -> String {
var freq = n.chars.freq
0..9 -> map { freq{_} \\ 0 }.join
}
 
for (var (p=2, i=1, nth=1, n=''); nth <= 20; (p.next_prime!, ++i)) {
n += Str(p)
var t = derived(n)
if (Num(t).is_prime){
if (t.len > 50) {
t = (t.first(20) + ' ... ' + t.last(20) + " (#{t.len} digits)")
}
printf("%2s: Index:%5d %s\n", nth, i, t)
++nth
}
}</syntaxhighlight>
{{out}}
<pre>
Smarandache-Wellen primes:
1: Index: 1 Last prime: 2 S-W: 2
2: Index: 2 Last prime: 3 S-W: 23
3: Index: 4 Last prime: 7 S-W: 2357
4: Index: 128 Last prime: 719 S-W: 23571113171923293137 ... 73677683691701709719 (355 digits)
5: Index: 174 Last prime: 1033 S-W: 23571113171923293137 ... 10131019102110311033 (499 digits)
6: Index: 342 Last prime: 2297 S-W: 23571113171923293137 ... 22732281228722932297 (1171 digits)
7: Index: 435 Last prime: 3037 S-W: 23571113171923293137 ... 30013011301930233037 (1543 digits)
8: Index: 1429 Last prime: 11927 S-W: 23571113171923293137 ... 11903119091192311927 (5719 digits)
 
Smarandache-Wellen derived primes:
1: Index: 32 4194123321127
2: Index: 72 547233879626521
3: Index: 73 547233979727521
4: Index: 134 13672766322929571043
5: Index: 225 3916856106393739943689
6: Index: 303 462696313560586013558131
7: Index: 309 532727113760586013758133
8: Index: 363 6430314317473636515467149
9: Index: 462 8734722823685889120488197
10: Index: 490 9035923128899919621189209
11: Index: 495 9036023329699969621389211
12: Index: 522 9337023533410210710923191219
13: Index: 538 94374237357103109113243102223
14: Index: 624 117416265406198131121272110263
15: Index: 721 141459282456260193137317129313
16: Index: 738 144466284461264224139325131317
17: Index: 790 156483290479273277162351153339
18: Index: 852 164518312512286294233375158359
19: Index: 1087 208614364610327343341589284471
20: Index: 1188 229667386663354357356628334581
</pre>
 
Line 1,108 ⟶ 1,216:
{{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