Miller–Rabin primality test: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed whitespace and comments, change indentations in program and output, simplified the genPrimes subroutine..) |
(→{{header|REXX}}: added more whitespace, simplified some statements.) |
||
Line 2,906: | Line 2,906: | ||
if accur=='' | accur==',' then accur= 10 /* " " " " " " */ |
if accur=='' | accur==',' then accur= 10 /* " " " " " " */ |
||
numeric digits max(200, 2*limit) /*we're dealing with some ginormous #s.*/ |
numeric digits max(200, 2*limit) /*we're dealing with some ginormous #s.*/ |
||
tell= accur<0 |
tell= accur<0; pad=left('', 7) /*show primes only if accur is negative*/ |
||
accur=abs(accur) |
accur=abs(accur); w=length(accur) /*use absolute value of ACCUR; get len.*/ |
||
call genPrimes limit /*suspenders now, use a belt later ··· */ |
call genPrimes limit /*suspenders now, use a belt later ··· */ |
||
@MRpt= 'Miller─Rabin primality test' /*define a character literal for SAY. */ |
|||
say "There are" |
say "There are" # 'primes ≤' limit /*might as well display some stuff. */ |
||
say /*nothing wrong with some whitespace. */ |
say /*nothing wrong with some whitespace. */ |
||
do a=2 to accur /*(skipping unity) do range of K's. */ |
do a=2 to accur /*(skipping unity) do range of K's. */ |
||
Line 2,919: | Line 2,919: | ||
if p==0 then iterate /*Not prime? Then try another number.*/ |
if p==0 then iterate /*Not prime? Then try another number.*/ |
||
mrp=mrp+1 /*well, found another one, by gum! */ |
mrp=mrp+1 /*well, found another one, by gum! */ |
||
if tell then say z 'is prime according to' @MRpt "with K="a |
if tell then say z 'is prime according to' @MRpt "with K="a |
||
if !.z then iterate |
if !.z then iterate |
||
say '[K='a"] " z "isn't prime !" /*oopsy─doopsy and/or whoopsy─daisy !*/ |
say '[K='a"] " z "isn't prime !" /*oopsy─doopsy and/or whoopsy─daisy !*/ |
||
end /*z*/ |
end /*z*/ |
||
say ' for 1──►'limit", K="right(a,length(accur))',', |
|||
@MRpt "found" |
say pad 'for 1──►'limit", K="right(a,w)',' @MRpt "found" mrp 'primes {out of' #"}." |
||
end /*a*/ |
end /*a*/ |
||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |