Primes whose first and last number is 3: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed a comment, elided the use of the prime semaphores.) |
|||
Line 348: | Line 348: | ||
Also, if a negative '''cols''' is specified, only the ''count'' of primes found is shown. |
Also, if a negative '''cols''' is specified, only the ''count'' of primes found is shown. |
||
<lang |
<lang rexx>/*REXX pgm finds and displays primes (base ten) that contain a leading and trailing 3. */ |
||
parse arg hi cols dig . /*obtain optional argument from the CL.*/ |
parse arg hi cols dig . /*obtain optional argument from the CL.*/ |
||
if hi=='' | hi=="," then hi= 4000 /*Not specified? Then use the default.*/ |
if hi=='' | hi=="," then hi= 4000 /*Not specified? Then use the default.*/ |
||
Line 383: | Line 383: | ||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
genP: @.1=2; @.2=3; @.3=5; @.4=7; @.5=11 /*define some low primes. */ |
genP: @.1=2; @.2=3; @.3=5; @.4=7; @.5=11 /*define some low primes. */ |
||
#=5; sq.#= @.# **2 /*number of primes so far; prime square*/ |
|||
#=5; sq.#= @.# **2 /*number of primes so far; prime². */ |
|||
do j=@.#+2 by 2 to hi-1 /*find odd primes from here on. */ |
do j=@.#+2 by 2 to hi-1 /*find odd primes from here on. */ |
||
parse var j '' -1 _; if _==5 then iterate /*J divisible by 5? (right dig)*/ |
parse var j '' -1 _; if _==5 then iterate /*J divisible by 5? (right dig)*/ |
||
Line 392: | Line 391: | ||
if j // @.k == 0 then iterate j /*Is J ÷ X? Then not prime. ___ */ |
if j // @.k == 0 then iterate j /*Is J ÷ X? Then not prime. ___ */ |
||
end /*k*/ /* [↑] only process numbers ≤ √ J */ |
end /*k*/ /* [↑] only process numbers ≤ √ J */ |
||
#= #+1; @.#= j; sq.#= j*j |
#= #+1; @.#= j; sq.#= j*j /*bump # of Ps; assign next P; P square*/ |
||
end /*j*/; |
end /*j*/; return</lang> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |