Smarandache prime-digital sequence: Difference between revisions

Added Easylang
m (syntax highlighting fixup automation)
(Added Easylang)
 
(6 intermediate revisions by 5 users not shown)
Line 273:
Largest Smarandache prime under 10000000: 7777753 (Smarandache prime 1903)
</pre>
 
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">spds: 2..∞ | select.first:100 'x ->
and? -> prime? x
-> every? digits x => prime?
 
print "First 25 SPDS primes:"
print first.n: 25 spds
 
print ""
print ["100th SPDS prime:" last spds]</syntaxhighlight>
 
{{out}}
 
<pre>First 25 SPDS primes:
2 3 5 7 23 37 53 73 223 227 233 257 277 337 353 373 523 557 577 727 733 757 773 2237 2273
 
100th SPDS prime: 33223</pre>
 
=={{header|AWK}}==
Line 521 ⟶ 539:
Ten thousandth SPDS prime: 273,322,727
Largest SPDS prime less than 1,000,000,000: 777,777,773
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
Uses the [[Extensible_prime_generator#Delphi|Delphi Prime-Generator Object]]
 
<syntaxhighlight lang="Delphi">
procedure ShowSmarandachePrimes(Memo: TMemo);
{Show primes where all digits are also prime}
var Sieve: TPrimeSieve;
var I,J,P,Count: integer;
var S: string;
 
 
function AllDigitsPrime(N: integer): boolean;
{Test all digits on N to see if they are prime}
var I,Count: integer;
var IA: TIntegerDynArray;
begin
Result:=False;
GetDigits(N,IA);
for I:=0 to High(IA) do
if not Sieve.Flags[IA[I]] then exit;
Result:=True;
end;
 
 
begin
Sieve:=TPrimeSieve.Create;
try
{Build 1 million primes}
Sieve.Intialize(1000000);
Count:=0;
{Test if all digits of the number are prime}
for I:=0 to Sieve.PrimeCount-1 do
begin
P:=Sieve.Primes[I];
if AllDigitsPrime(P) then
begin
Inc(Count);
if Count<=25 then Memo.Lines.Add(IntToStr(Count)+' - '+IntToStr(P));
if Count=100 then
begin
Memo.Lines.Add('100th = '+IntToStr(P));
break;
end;
end;
end;
finally Sieve.Free; end;
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
1 - 2
2 - 3
3 - 5
4 - 7
5 - 23
6 - 37
7 - 53
8 - 73
9 - 223
10 - 227
11 - 233
12 - 257
13 - 277
14 - 337
15 - 353
16 - 373
17 - 523
18 - 557
19 - 577
20 - 727
21 - 733
22 - 757
23 - 773
24 - 2237
25 - 2273
100th = 33223
Elapsed Time: 150.037 ms.
</pre>
 
 
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
n = 2
repeat
if isprim n = 1
h = n
while h > 0
d = h mod 10
if d < 2 or d = 4 or d = 6 or d > 7
break 1
.
h = h div 10
.
if h = 0
cnt += 1
if cnt <= 25
write n & " "
.
.
.
until cnt = 100
n += 1
.
print ""
print n
</syntaxhighlight>
 
{{out}}
<pre>
2 3 5 7 23 37 53 73 223 227 233 257 277 337 353 373 523 557 577 727 733 757 773 2237 2273
33223
</pre>
 
Line 826 ⟶ 971:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Smarandache_prime-digital_sequence}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Smarandache prime-digital sequence 01.png]]
In '''[https://formulae.org/?example=Smarandache_prime-digital_sequence this]''' page you can see the program(s) related to this task and their results.
 
'''Case 1. Show the first 25 SPDS primes'''
 
[[File:Fōrmulæ - Smarandache prime-digital sequence 02.png]]
 
[[File:Fōrmulæ - Smarandache prime-digital sequence 03.png]]
 
'''Case 2. Show the hundredth SPDS prime'''
 
[[File:Fōrmulæ - Smarandache prime-digital sequence 04.png]]
 
[[File:Fōrmulæ - Smarandache prime-digital sequence 05.png]]
 
'''Additional cases. Show the 1000-th, 10,000-th and 100,000th SPDS primes'''
 
[[File:Fōrmulæ - Smarandache prime-digital sequence 06.png]]
 
[[File:Fōrmulæ - Smarandache prime-digital sequence 07.png]]
 
[[File:Fōrmulæ - Smarandache prime-digital sequence 08.png]]
 
[[File:Fōrmulæ - Smarandache prime-digital sequence 09.png]]
 
[[File:Fōrmulæ - Smarandache prime-digital sequence 10.png]]
 
[[File:Fōrmulæ - Smarandache prime-digital sequence 11.png]]
 
=={{header|Go}}==
Line 1,875 ⟶ 2,046:
</pre>
 
=={{header|RPL}}==
Brute force being not an option for the slow machines that can run RPL, optimisation is based on a prime-digital number generator returning possibly prime numbers, e.g. not ending by 2 or 5.
<code>PRIM?</code> is defined at [[Primality by trial division#RPL|Primality by trial division]].
{| class="wikitable"
! RPL code
! Comment
|-
|
≪ { "2" "3" "5" "7" } DUP SIZE → digits base
≪ DUP SIZE 1 CF 2 SF
'''DO'''
'''IF''' DUP NOT '''THEN''' digits 1 GET ROT + SWAP 1 CF
'''ELSE'''
DUP2 DUP SUB digits SWAP POS
'''IF''' 2 FS?C '''THEN''' 2 == 4 ≪ 1 SF 2 ≫ IFTE
'''ELSE IF''' DUP base == '''THEN'''
SIGN 1 SF '''ELSE''' 1 + 1 CF '''END'''
'''END'''
digits SWAP GET REPL
LASTARG ROT DROP2 1 - '''END'''
'''UNTIL''' 1 FC? '''END''' DROP
≫ ≫ ‘<span style="color:blue">'''NSPDP'''</span>’ STO
|
<span style="color:blue">'''NSPDP'''</span> ''( "PDnumber" → "nextPDnumber" )''
rank = units position, carry = 0, 1st pass = true
Loop
If rank = 0 then add a new digit rank
Else
digit = ord[rank]
If first pass then next digit = 3 or 7
Else if digit is the last of the series
Then next digit = 1 otherwise = ++digit
Replace digit with next_digit
Rank--
Until no carry
return number as a string
|}
≪ { 2 3 5 } 7
'''WHILE''' OVER SIZE 100 < '''REPEAT'''
'''IF''' DUP <span style="color:blue">'''PRIM?'''</span> '''THEN''' SWAP OVER + SWAP '''END'''
STR→ <span style="color:blue">'''NSPDP'''</span> STR→ '''END''' DROP ≫ EVAL
DUP 1 25 SUB
SWAP 100 GET
{{out}}
<pre>
2: { 2 3 5 7 23 37 53 73 223 227 233 257 277 337 353 373 523 557 577 727 733 757 773 2237 2273 }
1: 33223
</pre>
task needs 3 min 45 s to run on a HP-48G.
=={{header|Rust}}==
<syntaxhighlight lang="rust">fn is_prime(n: u32) -> bool {
Line 2,083 ⟶ 2,304:
{{libheader|Wren-math}}
Simple brute-force approach.
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
 
var limit = 1000
2,041

edits