Concatenate two primes is also prime: Difference between revisions

m
→‎{{header|REXX}}: expanded output title, added/changed comments and whitespace.
m (→‎{{header|REXX}}: expanded output title, added/changed comments and whitespace.)
Line 481:
 
=={{header|REXX}}==
<lang rexx>/*REXX pgm finds & displays base ten neighbor primes P1 & P2, when concatenated, is also a prime.*/
parse arg hip cols . /*obtain optional arguments from the CL*/
if hip=='' | hip=="," then hip= 100 /*Not specified? Then use the default.*/
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
call genP /*build array of semaphores for primes.*/
title= ' concatenation of two neighbor primes (P1, P2) in base ten that results in a prime, ' ,
"a "prime, where P1 & P2 are <" " commas(hip)
w= 10 /*width of a number in any column. */
if cols>0 then say ' index │'center(title, 1 + cols*(w+1) )
Line 494:
do j=1 for ## /*search through specified primes. */
do k=1 for ##; cat2= @.j || @.k /*create a concatenated prime (base 10)*/
if !.cat2 then a.cat2= 1 /*flag it as being a "2cat" prime. */
end /*k*/ /* [↑] forgoes the need for sorting. */
end /*j*/
found= 0; idx= 1 idx= 1 /*initialize # of primes found; IDX. */
$=; do n=1 by 2 for hip**2%2 /*search for odd "cat2" primes. */
if \a.n then iterate /*search through allowable primes. */
Line 512:
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' commas(found) title
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 521:
#= 5; sq.#= @.#**2 /*the square of the highest low prime. */
do j=@.#+2 by 2 to hip**2-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 sq.k<=j /* [↓] divide by the known odd primes.*/
if j // @.k == 0 then iterate j /*Is J ÷ X? Then not prime. ___ */
Line 532 ⟶ 531:
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
index │ concatenation of two neighbor primes (P1, P2) in base ten that results in a prime, where P1 & P2 are < 100
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 23 37 53 73 113 137 173 193 197 211
Line 549 ⟶ 548:
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
 
Found 128 concatenation of two neighbor primes (P1, P2) in base ten that results in a prime, where P1 & P2 are < 100
</pre>