Anonymous user
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;
$= /*a list of substring primes (so far). */
do j=1 for #;
if verify(
if verify(
L= length(
do k=1 for L-1 /*test for primality for all substrings*/
do m=k+1 to L; y= substr(
if \!.y then iterate j /*does substring of
end /*m*/
end /*k*/
found= found + 1 /*bump the number of substring primes. */
$= $ right( commas(
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
parse var j '' -1 _;
if j//3==0 then
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= when using the default inputs:}}
<pre>
index │ primes (base ten) where all substrings are also primes, where N < 500
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
|