Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Fermat-numbers/REXX/fermat-numbers-1.rexx
Normal file
33
Task/Fermat-numbers/REXX/fermat-numbers-1.rexx
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*REXX program to find and display Fermat numbers, and show factors of Fermat numbers.*/
|
||||
parse arg n . /*obtain optional argument from the CL.*/
|
||||
if n=='' | n=="," then n= 9 /*Not specified? Then use the default.*/
|
||||
numeric digits 20 /*ensure enough decimal digits, for n=9*/
|
||||
|
||||
do j=0 to n; f= 2** (2**j) + 1 /*calculate a series of Fermat numbers.*/
|
||||
say right('F'j, length(n) + 1)': ' f /*display a particular " " */
|
||||
end /*j*/
|
||||
say
|
||||
do k=0 to n; f= 2** (2**k) + 1; say /*calculate a series of Fermat numbers.*/
|
||||
say center(' F'k": " f' ', 79, "═") /*display a particular " " */
|
||||
p= factr(f) /*factor a Fermat number, given time. */
|
||||
if words(p)==1 then say f ' is prime.'
|
||||
else say 'factors: ' p
|
||||
end /*k*/
|
||||
exit 0 /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
factr: procedure; parse arg x 1 z,,?
|
||||
do k=1 to 11 by 2; j= k; if j==1 then j= 2; if j==9 then iterate
|
||||
call build /*add J to the factors list. */
|
||||
end /*k*/ /* [↑] factor X with some low primes*/
|
||||
|
||||
do y=0 by 2; j= j + 2 + y // 4 /*ensure not ÷ by three. */
|
||||
parse var j '' -1 _; if _==5 then iterate /*last digit a "5"? Skip it.*/
|
||||
if j*j>x | j>z then leave
|
||||
call build /*add Y to the factors list. */
|
||||
end /*y*/ /* [↑] factor X with other higher #s*/
|
||||
j= z
|
||||
if z\==1 then ?= build()
|
||||
if ?='' then do; @.1= x; ?= x; #= 1; end
|
||||
return ?
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
build: do while z//j==0; z= z % j; ?= ? j; end; return strip(?)
|
||||
36
Task/Fermat-numbers/REXX/fermat-numbers-2.rexx
Normal file
36
Task/Fermat-numbers/REXX/fermat-numbers-2.rexx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*REXX program to find and display Fermat numbers, and show factors of Fermat numbers.*/
|
||||
parse arg n . /*obtain optional argument from the CL.*/
|
||||
if n=='' | n=="," then n= 9 /*Not specified? Then use the default.*/
|
||||
numeric digits 200 /*ensure enough decimal digits, for n=9*/
|
||||
|
||||
do j=0 to n; f= 2** (2**j) + 1 /*calculate a series of Fermat numbers.*/
|
||||
say right('F'j, length(n) + 1)': ' f /*display a particular " " */
|
||||
end /*j*/
|
||||
say
|
||||
do k=5 to n; f= 2** (2**k) + 1; say /*calculate a series of Fermat numbers.*/
|
||||
say center(' F'k": " f' ', 79, "═") /*display a particular " " */
|
||||
a= rho(f) /*factor a Fermat number, given time. */
|
||||
b= f % a
|
||||
if a==b then say f ' is prime.'
|
||||
else say 'factors: ' commas(a) " " commas(b)
|
||||
end /*k*/
|
||||
exit 0 /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
commas: parse arg _; do ?=length(_)-3 to 1 by -3; _=insert(',', _, ?); end; return _
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
rho: procedure; parse arg n; y= 2; d= 1 /*initialize X, Y, and D variables.*/
|
||||
do x=2 until d==n /*try rho method with X=2 for 1st time.*/
|
||||
do while d==1
|
||||
x= (x*x + 1) // n
|
||||
v= (y*y + 1) // n
|
||||
y= (v*v + 1) // n
|
||||
parse value x-y with xy 1 sig 2 /*obtain sign of the x-y difference. */
|
||||
if sig=='-' then parse var xy 2 xy /*Negative? Then use absolute value. */
|
||||
nn= n
|
||||
do until nn==0
|
||||
parse value xy//nn nn with nn xy /*assign two variables: NN and XY */
|
||||
end /*until*/ /*this is an in-line GCD function. */
|
||||
d= xy /*assign variable D with a new XY */
|
||||
end /*while*/
|
||||
end /*x*/
|
||||
return d /*found a factor of N. Return it.*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue