Substring primes: Difference between revisions
Content added Content deleted
(add FreeBASIC) |
m (→{{header|REXX}}: (to avoid name calling) elided primality test counting) |
||
Line 194: | Line 194: | ||
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 /*bump count of the # primality tests. */ |
|||
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.*/ |
||
ptests= ptests + 1 /*bump count of the # primality tests. */ |
|||
if \!.y then iterate j /*does substring of X not prime? Skip.*/ |
if \!.y then iterate j /*does substring of X not prime? Skip.*/ |
||
end /*m*/ |
end /*m*/ |
||
Line 207: | Line 205: | ||
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 'Found ' words($) @sprs |
||
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. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
Line 232: | Line 229: | ||
Found 9 primes (base ten) where all substrings are also primes < 500 |
Found 9 primes (base ten) where all substrings are also primes < 500 |
||
14 primality tests were performed. |
|||
</pre> |
</pre> |
||