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