Smarandache prime-digital sequence: Difference between revisions

Added Easylang
m (→‎{{header|Phix}}: %V->%v, missing commas in fmts, plus it's gotten a touch slower somehow.)
(Added Easylang)
 
(16 intermediate revisions by 10 users not shown)
Line 19:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F divisors(n)
V divs = [1]
L(ii) 2 .< Int(n ^ 0.5) + 3
Line 59:
print(item, end' ‘ ’)
print()
print(‘Hundredth SPDS prime: ’seq[99])</langsyntaxhighlight>
 
{{out}}
Line 70:
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<langsyntaxhighlight Actionlang="action!">INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
 
BYTE FUNC IsZero(REAL POINTER a)
Line 150:
a==+1
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Smarandache_prime-digital_sequence.png Screenshot from Atari 8-bit computer]
Line 163:
Uses a sieve to find primes. Requires --heap 256m for Algol 68G.
<br>Uses the optimisations of the Factor, Phix, etc. samples.
<langsyntaxhighlight lang="algol68"># find elements of the Smarandache prime-digital sequence - primes whose #
# digits are all primes #
# Uses the observations that the final digit of 2 or more digit Smarandache #
Line 264:
)
)
END</langsyntaxhighlight>
{{out}}
<pre>
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}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f SMARANDACHE_PRIME-DIGITAL_SEQUENCE.AWK
BEGIN {
Line 314 ⟶ 332:
return(1)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 320 ⟶ 338:
100: 33223
</pre>
 
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="freebasic">arraybase 1
dim smar(100)
smar[1] = 2
 
cont = 1
i = 1
 
print 1, 2
while cont < 100
i += 2
if not isPrime(i) then continue while
for j = 1 to length(string(i))
digit = int(mid(string(i),j,1))
if not isPrime(digit) then continue while
next j
cont += 1
smar[cont] = i
if cont = 100 or cont <= 25 then print cont, smar[cont]
end while
end
 
function isPrime(v)
if v < 2 then return False
if v mod 2 = 0 then return v = 2
if v mod 3 = 0 then return v = 3
d = 5
while d * d <= v
if v mod d = 0 then return False else d += 2
end while
return True
end function</syntaxhighlight>
{{out}}
<pre>Igual que la entrada de FreeBASIC.</pre>
 
 
=={{header|C}}==
{{trans|C++}}
<langsyntaxhighlight lang="c">#include <locale.h>
#include <stdbool.h>
#include <stdint.h>
Line 393 ⟶ 448:
printf("Largest SPDS prime less than %'u: %'u\n", limit, max);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 406 ⟶ 461:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <cstdint>
 
Line 474 ⟶ 529:
std::cout << "Largest SPDS prime less than " << limit << ": " << max << '\n';
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 484 ⟶ 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>
 
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_function Extensible Prime Generator (F#)]
<langsyntaxhighlight lang="fsharp">
// Generate Smarandache prime-digital sequence. Nigel Galloway: May 31st., 2019
let rec spds g=seq{yield! g; yield! (spds (Seq.collect(fun g->[g*10+2;g*10+3;g*10+5;g*10+7]) g))}|>Seq.filter(isPrime)
Line 494 ⟶ 676:
printfn "\n\n100th item of this sequence is %d" (spds [2;3;5;7] |> Seq.item 99)
printfn "1000th item of this sequence is %d" (spds [2;3;5;7] |> Seq.item 999)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 530 ⟶ 712:
=={{header|Factor}}==
===Naive===
<langsyntaxhighlight lang="factor">USING: combinators.short-circuit io lists lists.lazy math
math.parser math.primes prettyprint sequences ;
IN: rosetta-code.smarandache-naive
Line 547 ⟶ 729:
"100th member: " write smarandache 99 [ cdr ] times car . ;
 
MAIN: smarandache-demo</langsyntaxhighlight>
{{out}}
<pre>
Line 582 ⟶ 764:
 
===Optimized===
<langsyntaxhighlight lang="factor">USING: combinators generalizations io kernel math math.functions
math.primes prettyprint sequences ;
IN: rosetta-code.smarandache
Line 636 ⟶ 818:
] each ;
 
MAIN: smarandache-demo</langsyntaxhighlight>
{{out}}
<pre>
Line 673 ⟶ 855:
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">: is_prime? ( n -- flag )
dup 2 < if drop false exit then
dup 2 mod 0= if 2 = exit then
Line 720 ⟶ 902:
1000 spds_nth . cr
 
bye</langsyntaxhighlight>
 
{{out}}
Line 731 ⟶ 913:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">
function isprime( n as ulongint ) as boolean
if n < 2 then return false
Line 757 ⟶ 939:
print count, smar(count)
end if
wend</langsyntaxhighlight>
{{out}}
<pre>
Line 789 ⟶ 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}}==
===Basic===
<langsyntaxhighlight lang="go">package main
 
import (
Line 850 ⟶ 1,058:
n = listSPDSPrimes(n+2, indices[i-1], indices[i], true)
}
}</langsyntaxhighlight>
 
{{out}}
Line 897 ⟶ 1,105:
 
This is more than 30 times faster than the above version (runs in about 12.5 seconds on my Celeron @1.6GHx) and could be quickened up further (to around 4 seconds) by using a wrapper for GMP rather than Go's native big.Int type.
<langsyntaxhighlight lang="go">package main
 
import (
Line 984 ⟶ 1,192:
n = listSPDSPrimes(n.AddTwo(), indices[i-1], indices[i], true)
}
}</langsyntaxhighlight>
 
{{out}}
Line 993 ⟶ 1,201:
=={{header|Haskell}}==
Using the optimized approach of generated numbers from prime digits and testing for primality.
<langsyntaxhighlight lang="haskell">{-# LANGUAGE NumericUnderscores #-}
import Control.Monad (guard)
import Math.NumberTheory.Primes.Testing (isPrime)
Line 1,021 ⟶ 1,229:
mapM_ (uncurry (printf "The %9sth SPDS: %15s\n")) $
nextSPDSTerms [100, 1_000, 10_000, 100_000, 1_000_000]
where f = show . take 25</langsyntaxhighlight>
{{out}}
<pre>The first 25 SPDS:
Line 1,057 ⟶ 1,265:
=={{header|Java}}==
Generate next in sequence directly from previous, inspired by previous solutions.
<langsyntaxhighlight lang="java">
public class SmarandachePrimeDigitalSequence {
 
Line 1,140 ⟶ 1,348:
 
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,159 ⟶ 1,367:
 
See e.g. [[Erd%C5%91s-primes#jq]] for a suitable implementation of `is_prime` as used here.
<langsyntaxhighlight lang="jq">def Smarandache_primes:
# Output: a naively constructed stream of candidate strings of length >= 1
def Smarandache_candidates:
Line 1,186 ⟶ 1,394:
 
# jq counts from 0 so:
"\nThe hundredth: \(nth(99; Smarandache_primes))"</langsyntaxhighlight>
{{out}}
<pre>
Line 1,201 ⟶ 1,409:
add numbers that end in 3 or 7 and that only contain 2, 3, 5, and 7. This
can be done via permutations of combinations with repetition.
<langsyntaxhighlight lang="julia">
using Combinatorics, Primes
 
Line 1,227 ⟶ 1,435:
println("The 100th Smarandache prime is: ", v[100])
println("The 10000th Smarandache prime is: ", v[10000])
</langsyntaxhighlight>{{out}}
<pre>
The first 25 Smarandache primes are: [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]
Line 1,235 ⟶ 1,443:
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">-- FUNCS:
local function T(t) return setmetatable(t, {__index=table}) end
table.firstn = function(t,n) local s=T{} n=n>#t and #t or n for i = 1,n do s[i]=t[i] end return s end
Line 1,252 ⟶ 1,460:
end
print("1-25 : " .. spds:firstn(25):concat(" "))
print("100th: " .. spds[100])</langsyntaxhighlight>
{{out}}
<pre>1-25 : 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
Line 1,258 ⟶ 1,466:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[SmarandachePrimeQ]
SmarandachePrimeQ[n_Integer] := MatchQ[IntegerDigits[n], {(2 | 3 | 5 | 7) ..}] \[And] PrimeQ[n]
s = Select[Range[10^5], SmarandachePrimeQ];
Take[s, UpTo[25]]
s[[100]]</langsyntaxhighlight>
{{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}
Line 1,268 ⟶ 1,476:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import math, strformat, strutils
 
const N = 35_000
Line 1,318 ⟶ 1,526:
inc count
if count == 100:
echo "The 100th SPDS is: ", n</langsyntaxhighlight>
 
{{out}}
Line 1,328 ⟶ 1,536:
uses [[http://rosettacode.org/wiki/Extensible_prime_generator#Pascal:Extensible_prime_generator]]<BR>
Simple Brute force.Testing for prime takes most of the time.
<langsyntaxhighlight lang="pascal">program Smarandache;
 
uses
Line 1,399 ⟶ 1,607:
inc(DgtLimit);
until DgtLimit= 12;
end.</langsyntaxhighlight>
{{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
Line 1,409 ⟶ 1,617:
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 1,431 ⟶ 1,639:
 
say 'Smarandache prime-digitals:';
printf "%22s: %s\n", ucfirst(num2en_ordinal($_)), $spds[$_-1] for 1..25, 100, 1000, 10_000, 100_000;</langsyntaxhighlight>
{{out}}
<pre> First: 2
Line 1,474 ⟶ 1,682:
but because of the massive gaps (eg between 777,777,777 and 2,222,222,223) it proved much faster
to test each candidate for primality individually. Timings below show just how much this improves things.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()</span>
Line 1,525 ⟶ 1,733:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,546 ⟶ 1,754:
 
=={{header|Python}}==
<syntaxhighlight lang="python">
<lang Python>
def divisors(n):
divs = [1]
Line 1,592 ⟶ 1,800:
pass
print(100, generator.__next__())
</syntaxhighlight>
</lang>
 
<b>Output</b>
<syntaxhighlight lang="python">
<lang Python>
1 2
2 3
Line 1,612 ⟶ 1,820:
15 353
100 33223
</syntaxhighlight>
</lang>
 
=={{header|Quackery}}==
 
<code>isprime</code> is defined at [[Primality by trial division#Quackery]].
 
===Naive===
 
<syntaxhighlight lang="quackery"> [ true swap
[ 10 /mod
[ table 1 1 0 0 1 0 1 0 1 1 ]
iff [ dip not ] done
dup 0 = until ]
drop ] is digitsprime ( n --> b )
 
[ temp put [] 0
[ dup digitsprime if
[ dup isprime if
[ dup dip join ] ]
1+
over size temp share = until ]
drop ] is spds ( n --> [ )
 
100 spds
25 split swap echo
cr cr
-1 peek echo</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>
 
===Optimised===
 
Not the same as the Factor and Factor inspired solutions, which count in base 4 with leading zeros like a telescoping pedometer; this skips over base 5 numbers with zeros in them.
 
<syntaxhighlight lang="quackery"> [ 0 over
[ 5 /mod 0 = while
dip [ 5 * 1+ ]
again ]
drop + ] is skipzeros ( n --> n )
 
[ [] swap
[ 5 /mod
[ table 0 2 3 5 7 ]
rot join swap
dup 0 = until ]
swap witheach
[ swap 10 * + ] ] is primedigits ( n --> n )
 
 
[ temp put [] 0
[ 1+ skipzeros
dup primedigits
dup isprime iff
[ swap dip join ]
else drop
over size
temp share = until ]
temp release drop ] is spds ( n --> [ )
 
100 spds
25 split swap echo
cr cr
-1 peek echo</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>
 
=={{header|Raku}}==
(formerly Perl 6)
{{libheader|ntheory}}
 
<syntaxhighlight lang="raku" perl6line>use Lingua::EN::Numbers;
use ntheory:from<Perl5> <:all>;
 
# Implemented as a lazy, extendable list
my $spds = grep { .&is_prime }, flat [2,3,5,7], [23,27,33,37,53,57,73,77], -> $p
{ state $o++; my $oom = 10**(1+$o); [ flat (2,3,5,7).map: -> $l { (|$p).map: $l*$oom + * } ] } … *;
 
say 'Smarandache prime-digitals:';
printf "%22s: %s\n", ordinal(1+$_).tclc, comma $spds[$_] for flat ^25, 99, 999, 9999, 99999;</langsyntaxhighlight>
{{out}}
<pre>Smarandache prime-digitals:
Line 1,660 ⟶ 1,940:
=={{header|REXX}}==
The prime number generator has been simplified and very little optimization was included.
<langsyntaxhighlight lang="rexx">/*REXX program lists a sequence of SPDS (Smarandache prime-digital sequence) primes.*/
parse arg n q /*get optional number of primes to find*/
if n=='' | n=="," then n= 25 /*Not specified? Then use the default.*/
Line 1,689 ⟶ 1,969:
end /*j*/ /* [↑] only display N number of primes*/
if ox<0 then say right(z, 21) /*display one (the last) SPDS prime. */
return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 1,727 ⟶ 2,007:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
 
Line 1,756 ⟶ 2,036:
ok
next
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 1,766 ⟶ 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}}==
<langsyntaxhighlight lang="rust">fn is_prime(n: u32) -> bool {
if n < 2 {
return false;
Line 1,839 ⟶ 2,169:
println!("Largest SPDS prime less than {}: {}", limit, p);
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,853 ⟶ 2,183:
=={{header|Ruby}}==
Attaching 3 and 7 to permutations of 2,3,5 and 7
<langsyntaxhighlight lang="ruby">require "prime"
smarandache = Enumerator.new do|y|
Line 1,870 ⟶ 2,200:
p seq.first(25)
p seq.last
</syntaxhighlight>
</lang>
{{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]
Line 1,878 ⟶ 2,208:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">func is_prime_digital(n) {
n.is_prime && n.digits.all { .is_prime }
}
 
say is_prime_digital.first(25).join(',')
say is_prime_digital.nth(100)</langsyntaxhighlight>
{{out}}
<pre>
Line 1,892 ⟶ 2,222:
=={{header|Swift}}==
{{trans|C++}}
<langsyntaxhighlight lang="swift">func isPrime(number: Int) -> Bool {
if number < 2 {
return false
Line 1,959 ⟶ 2,289:
max = n
}
print("Largest SPDS prime less than \(limit): \(max)")</langsyntaxhighlight>
 
{{out}}
Line 1,974 ⟶ 2,304:
{{libheader|Wren-math}}
Simple brute-force approach.
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int
 
var limit = 1000
Line 2,002 ⟶ 2,332:
System.print(spds.take(25).toList)
System.print("\nThe 100th SPDS prime is %(spds[99])")
System.print("\nThe 1,000th SPDS prime is %(spds[999])")</langsyntaxhighlight>
 
{{out}}
Line 2,013 ⟶ 2,343:
The 1,000th SPDS prime is 3273527
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then \even >2\ return false;
for I:= 3 to sqrt(N) do
[if rem(N/I) = 0 then return false;
I:= I+1;
];
return true;
];
 
func PrimeDigits(N); \Return 'true' if all digits are prime
int N;
[repeat N:= N/10;
case rem(0) of
0, 1, 4, 6, 8, 9: return false
other [];
until N = 0;
return true;
];
 
int C, N;
[C:= 0; N:= 2;
loop [if IsPrime(N) then
if PrimeDigits(N) then
[C:= C+1;
if C <= 25 then
[IntOut(0, N); ChOut(0, ^ )];
if C = 100 then
[Text(0, "^m^j100th: "); IntOut(0, N)];
if C = 1000 then quit;
];
N:= N+1;
];
Text(0, "^m^j1000th: "); IntOut(0, N); CrLf(0);
]</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
100th: 33223
1000th: 3273527
</pre>
 
=={{header|Yabasic}}==
{{trans|Ring}}
<syntaxhighlight lang="yabasic">num = 0
limit = 26
limit100 = 100
 
print "First 25 Smarandache primes:\n"
for n = 1 to 34000
flag = 0
nStr$ = str$(n)
for x = 1 to len(nStr$)
nx = val(mid$(nStr$,x,1))
if isPrime(n) and isPrime(nx) then
flag = flag + 1
else
break
end if
next
if flag = len(nStr$) then
num = num + 1
if num < limit print "", n, " ";
if num = limit100 print "\n\n100th Smarandache prime: ", n
end if
next n
end
 
sub isPrime(v)
if v < 2 return False
if mod(v, 2) = 0 return v = 2
if mod(v, 3) = 0 return v = 3
d = 5
while d * d <= v
if mod(v, d) = 0 then return False else d = d + 2 : fi
wend
return True
end sub</syntaxhighlight>
{{out}}
<pre>Igual que la entrada de Ring.</pre>
 
 
=={{header|zkl}}==
Line 2,020 ⟶ 2,435:
 
[[Extensible prime generator#zkl]] could be used instead.
<langsyntaxhighlight lang="zkl">var [const] BI=Import("zklBigNum"); // libGMP
 
spds:=Walker.zero().tweak(fcn(ps){
Line 2,027 ⟶ 2,442:
if(p.split().filter( fcn(n){ 0==nps[n] }) ) return(Void.Skip);
p // 733 --> (7,3,3) --> () --> good, 29 --> (2,9) --> (9) --> bad
}.fp(BI(1)));</langsyntaxhighlight>
Or
<langsyntaxhighlight lang="zkl">spds:=Walker.zero().tweak(fcn(ps){
var [const] nps="014689".inCommon;
p:=ps.nextPrime().toInt();
if(nps(p.toString())) return(Void.Skip);
p // 733 --> "" --> good, 29 --> "9" --> bad
}.fp(BI(1)));</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">println("The first 25 terms of the Smarandache prime-digital sequence are:");
spds.walk(25).concat(",").println();
 
println("The hundredth term of the sequence is: ",spds.drop(100-25).value);
println("1000th item of this sequence is : ",spds.drop(1_000-spds.n).value);</langsyntaxhighlight>
{{out}}
<pre>
1,995

edits