Smarandache prime-digital sequence: Difference between revisions

(Added Fōrmulæ solution)
Line 1,058:
10,000th Smarandache prime-digital sequence number = 273322727
100,000th Smarandache prime-digital sequence number = 23325232253
</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
See the preamble to the [[#Julia|Julia]] entry for the rationale behind the following implementation.
 
See e.g. [[Erd%C5%91s-primes#jq]] for a suitable implementation of `is_prime` as used here.
<lang jq>def Smarandache_primes:
# Output: a naively constructed stream of candidate strings of length >= 2
def Smarandache_candidates:
def unconstrained($length):
if $length==1 then "2", "3", "5", "7"
else ("2", "3", "5", "7") as $n
| $n + unconstrained($length -1 )
end;
unconstrained(. - 1) as $u
| ("3", "7") as $tail
| $u + $tail ;
 
2,3,5,7,
(range(2; infinite) | Smarandache_candidates | tonumber | select(is_prime));
 
# Override jq's incorrect definition of nth/2
# Emit the $n-th value of the stream, counting from 0; or emit nothing
def nth($n; s):
if $n < 0 then error("nth/2 doesn't support negative indices")
else label $out
| foreach s as $x (-1; .+1; select(. >= $n) | $x, break $out)
end;
 
"First 25:",
[limit(25; Smarandache_primes)],
 
# jq counts from 0 so:
"\nThe hundredth: \(nth(99; Smarandache_primes))"</lang>
{{out}}
<pre>
jq -nrc -f rc-smarandache-primes.jq
First 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]
 
The hundredth: 33223
</pre>
 
2,442

edits