Jump to content

Substring primes: Difference between revisions

m
→‎{{header|REXX}}: added a count for the number of primality tests performed.
m (→‎{{header|Phix}}: prefer get_prime())
m (→‎{{header|REXX}}: added a count for the number of primality tests performed.)
Line 172:
if verify(x2, 25 , 'M')>0 then iterate /* " X2 part " " " " " */
L= length(x) /*obtain the length of the X prime.*/
ptests= ptests + 1
do k=1 for L-1 /*test for primality for all substrings*/
do m=k+1 to L; y= substr(x, k, m-1) /*extract a substring from the X prime.*/
Line 182 ⟶ 183:
 
if $\=='' then say center(1,7)"│" substr($, 2) /*display the list of substring primes.*/
say; say 'Found ' words($) @sprs
say
say; 'Found ' words($) say ptests ' primality tests @sprswere performed.'
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: !.= 0; ptests= 0 /*placeholders for primes (semaphores).*/
@.1=2; @.2=3; @.3=5; @.4=7; @.5=11 /*define some low primes. */
!.2=1; !.3=1; !.5=1; !.7=1; !.11=1 /* " " " " flags. */
Line 208 ⟶ 209:
 
Found 9 primes (base ten) where all substrings are also primes < 500
 
12 primality tests were performed.
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.