Twin primes: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) (Added Perl entry) |
m (→{{header|REXX}}: optimized the GENP function.) |
||
Line 611: | Line 611: | ||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
genP: arg y; @.1=2; @.2=3; @.3=5; @.4=7; @.5=11; @.6=13; #= 5; tp= 2; s= @.# + 2 |
genP: arg y; @.1=2; @.2=3; @.3=5; @.4=7; @.5=11; @.6=13; #= 5; tp= 2; s= @.# + 2 |
||
do j=s by 2 while j<y |
do j=s by 2 while j<y /*continue on with the next odd prime. */ |
||
parse var j '' -1 _ /*obtain the last digit of the J var.*/ |
parse var j '' -1 _ /*obtain the last digit of the J var.*/ |
||
if _ ==5 then iterate /*is this integer a multiple of five? */ |
if _ ==5 then iterate /*is this integer a multiple of five? */ |
||
Line 622: | Line 622: | ||
end /*k*/ /* [↑] only divide up to √ J */ |
end /*k*/ /* [↑] only divide up to √ J */ |
||
#= #+1 /*bump the count of number of primes. */ |
#= #+1 /*bump the count of number of primes. */ |
||
@.#= j; |
@.#= j; _= # - 1 /*define J prime; point to prev. prime.*/ |
||
if j-2\==@._ then iterate /*This & previous prime not twins? Skip*/ |
if j-2\==@._ then iterate /*This & previous prime not twins? Skip*/ |
||
tp= tp + 1 /*bump count of twin pairs (both are<Y)*/ |
|||
end /*j*/ |
end /*j*/ |
||
return tp</lang> |
return tp</lang> |