Substring primes: Difference between revisions

m
→‎{{header|REXX}}: changed comments and some variable names.
(Added Go)
m (→‎{{header|REXX}}: changed comments and some variable names.)
Line 558:
say ' index │'center(title, 1 + cols*(w+1) ) /*display the title of the output. */
say '───────┼'center("" , 1 + cols*(w+1), '─') /* " " separator " " " */
found= 0; idx= 1 idx= 1 /*define # substring primes found; IDX.*/
$= /*a list of substring primes (so far). */
do j=1 for #; xp= @.j; x2p2= substr(xp, 2) /*search for primes that fit criteria. */
if verify(xp, 014689, 'M')>0 then iterate /*does Xit prime havecontain any of these digsdigits? */
if verify(x2p2, 25 , 'M')>0 then iterate /* " X2P2 part " " " " " */
L= length(xp) /*obtain the length of the XP prime.*/
do k=1 for L-1 /*test for primality for all substrings*/
do m=k+1 to L; y= substr(xp, k, m-1) /*extract a substring from the XP prime.*/
if \!.y then iterate j /*does substring of XP not prime? Skip.*/
end /*m*/
end /*k*/
 
found= found + 1 /*bump the number of substring primes. */
$= $ right( commas(jp), w) /*add a substring prime ──► $ list. */
if found//cols\==0 then iterate /*have we populated a line of output? */
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
Line 589:
#=5; s.#= @.# **2 /*number of primes so far; prime². */
/* [↓] generate more primes ≤ high.*/
do j=@.#+2 by 2 to n -1 /*find odd primes from here on. */
parse var j '' -1 _; if if _==5 then iterate /*J divisible÷ by 5? (right digdigit)*/
if j//3==0 then iterate; if j// 37==0 then iterate /*" " " 3?; J ÷ by 7? */
if j// 7==0 then iterate /*" " " 7? */
do k=5 while s.k<=j /* [↓] divide by the known odd primes.*/
if j // @.k == 0 then iterate j /*Is J ÷ X? Then not prime. ___ */
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; s.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
end /*j*/; return</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
index │ primes (base ten) where all substrings are also primes, where N < 500
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 12 23 3 5 4 7 9 23 12 37 16 53 21 73 74373
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────