Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
18
Task/Factorial/REXX/factorial-1.rexx
Normal file
18
Task/Factorial/REXX/factorial-1.rexx
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/*REXX pgm computes & shows the factorial of a non─negative integer, and also its length*/
|
||||
numeric digits 100000 /*100k digits: handles N up to 25k.*/
|
||||
parse arg n /*obtain optional argument from the CL.*/
|
||||
if n='' then call er 'no argument specified.'
|
||||
if arg()>1 | words(n)>1 then call er 'too many arguments specified.'
|
||||
if \datatype(n,'N') then call er "argument isn't numeric: " n
|
||||
if \datatype(n,'W') then call er "argument isn't a whole number: " n
|
||||
if n<0 then call er "argument can't be negative: " n
|
||||
!= 1 /*define the factorial product (so far)*/
|
||||
do j=2 to n; !=!*j /*compute the factorial the hard way. */
|
||||
end /*j*/ /* [↑] where da rubber meets da road. */
|
||||
|
||||
say n'! is ['length(!) "digits]:" /*display number of digits in factorial*/
|
||||
say /*add some whitespace to the output. */
|
||||
say ! /*display the factorial product──►term.*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
er: say; say '***error***'; say; say arg(1); say; exit 13
|
||||
22
Task/Factorial/REXX/factorial-2.rexx
Normal file
22
Task/Factorial/REXX/factorial-2.rexx
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*REXX program computes the factorial of a non─negative integer, and it automatically */
|
||||
/*────────────────────── adjusts the number of decimal digits to accommodate the answer.*/
|
||||
numeric digits 99 /*99 digits initially, then expanded. */
|
||||
parse arg n /*obtain optional argument from the CL.*/
|
||||
if n='' then call er 'no argument specified'
|
||||
if arg()>1 | words(n)>1 then call er 'too many arguments specified.'
|
||||
if \datatype(n,'N') then call er "argument isn't numeric: " n
|
||||
if \datatype(n,'W') then call er "argument isn't a whole number: " n
|
||||
if n<0 then call er "argument can't be negative: " n
|
||||
!= 1 /*define the factorial product (so far)*/
|
||||
do j=2 to n; !=!*j /*compute the factorial the hard way. */
|
||||
if pos(.,!)==0 then iterate /*is the ! in exponential notation? */
|
||||
parse var ! 'E' digs /*extract exponent of the factorial, */
|
||||
numeric digits digs + digs % 10 /* ··· and increase it by ten percent.*/
|
||||
end /*j*/ /* [↑] where da rubber meets da road. */
|
||||
!= !/1 /*normalize the factorial product. */
|
||||
say n'! is ['length(!) "digits]:" /*display number of digits in factorial*/
|
||||
say /*add some whitespace to the output. */
|
||||
say ! /*display the factorial product ──►term*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
er: say; say '***error!***'; say; say arg(1); say; exit 13
|
||||
27
Task/Factorial/REXX/factorial-3.rexx
Normal file
27
Task/Factorial/REXX/factorial-3.rexx
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*REXX program computes & shows the factorial of an integer, striping trailing zeroes. */
|
||||
numeric digits 200 /*start with two hundred digits. */
|
||||
parse arg N . /*obtain an optional argument from CL. */
|
||||
if N=='' | N=="," then N= 0 /*Not specified? Then use the default.*/
|
||||
!= 1 /*define the factorial product so far. */
|
||||
do j=2 to N /*compute factorial the hard way. */
|
||||
old!= ! /*save old product in case of overflow.*/
|
||||
!= ! * j /*multiple the old factorial with J. */
|
||||
if pos(.,!) \==0 then do /*is the ! in exponential notation?*/
|
||||
d= digits() /*D temporarily stores number digits.*/
|
||||
numeric digits d+d%10 /*add 10% to the decimal digits. */
|
||||
!= old! * j /*re─calculate for the "lost" digits.*/
|
||||
end /*IFF ≡ if and only if. [↓] */
|
||||
parse var ! '' -1 _ /*obtain the right-most digit of ! */
|
||||
if _==0 then != strip(!, , 0) /*strip trailing zeroes IFF the ... */
|
||||
end /*j*/ /* [↑] ... right-most digit is zero. */
|
||||
z= 0 /*the number of trailing zeroes in ! */
|
||||
do v=5 by 0 while v<=N /*calculate number of trailing zeroes. */
|
||||
z= z + N % v /*bump Z if multiple power of five.*/
|
||||
v= v * 5 /*calculate the next power of five. */
|
||||
end /*v*/ /* [↑] we only advance V by ourself.*/
|
||||
/*stick a fork in it, we're all done. */
|
||||
!= ! || copies(0, z) /*add water to rehydrate the product. */
|
||||
if z==0 then z= 'no' /*use gooder English for the message. */
|
||||
say N'! is ['length(!) " digits with " z ' trailing zeroes]:'
|
||||
say /*display blank line (for whitespace).*/
|
||||
say ! /*display the factorial product. */
|
||||
Loading…
Add table
Add a link
Reference in a new issue