Jump to content

Special factorials: Difference between revisions

→‎{{header|REXX}}: added the computer programming language REXX.
m (→‎{{header|REXX}}: added a stub for REXX.)
(→‎{{header|REXX}}: added the computer programming language REXX.)
Line 184:
 
=={{header|REXX}}==
<lang rexx>/*REXX program to compute some special factorials: superfactorials, hyperfactorials,*/
/*───────────────────────────────────── alternating factorials, exponential factorials.*/
numeric digits 100 /*allow humonous numbers to be computed*/
parse arg LO HI nef xef nrf xrf /*obtain optional arguments from the CL*/
if LO=='' | LO=="," then LO= 0 /*Not specified? Then use the default.*/
if HI=='' | HI=="," then HI= 9 /* " " " " " " */
if nef=='' | nef=="," then nef= 5 /* " " " " " " */
if xef=='' | xef=="," then xef= nef /* " " " " " " */
if nrf=='' | nrf=="," then nrf= 10 /* " " " " " " */
if nef=='' | nef=="," then nef= 5 /* " " " " " " */
if xrf=='' | xrf=="," then xrf= 119 /* " " " " " " */
num= HI-LO+1 /*calculate the # of numbers to be used*/
call hdr num, 'super'; do j=LO to HI; $= $ sf(j); end; call tell
call hdr num, 'hyper'; do j=LO to HI; $= $ hf(j); end; call tell
call hdr num, 'alternating '; do j=LO to HI; $= $ af(j); end; call tell
call hdr nef, 'exponential '; do j=0 for nef; $= $ ef(j); end; call tell
@= 'the number of decimal digits in the exponential factorial of '
say @ xef " is:"; $= ' 'commas( efn( ef( xef) ) ); call tell
@= 'the inverse factorial of '
do j=1 for nrf; fp= !(j); say @ fp " is: " rf(fp)
end /*j*/
say @ xrf " is: " rf(xrf)
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
!: procedure; parse arg x; != 1; do #=2 to x; != ! * #; end; return !
af: procedure; parse arg x; if x==0 then return 0; prev= 0; call af!; return !
af!: do #=1 for x; != !(#) - prev; prev= !; end; return !
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
ef: procedure; parse arg x; if x==0 | x==1 then return 1; return x**ef(x-1)
efn: procedure; arg x; numeric digits 9; x= x; parse var x 'E' d; return d+1
sf: procedure; parse arg x; != 1; do #=2 to x; != ! * !(#); end; return !
hf: procedure; parse arg x; != 1; do #=2 to x; != ! * #**#; end; return !
hdr: parse arg nn,what,,$; say 'the first ' nn " "what'factorials:'; return
tell: say substr($, 2); say; $=; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
rf: procedure; parse arg x,u; do #=0 until f>x; f=!(#); if x==f then return #; end
return 'undefined'</lang>
{{out|output|text=&nbsp; when using the internal default input:}}
<pre>
the first 10 superfactorials:
1 1 2 12 288 34560 24883200 125411328000 5056584744960000 1834933472251084800000
 
the first 10 hyperfactorials:
1 1 4 108 27648 86400000 4031078400000 3319766398771200000 55696437941726556979200000 21577941222941856209168026828800000
 
the first 10 alternating factorials:
0 1 1 5 19 101 619 4421 35899 326981
 
the first 5 exponential factorials:
1 1 2 9 262144
 
the number of decimal digits in the exponential factorial of 5 is:
183,231
 
the inverse factorial of 1 is: 0
the inverse factorial of 2 is: 2
the inverse factorial of 6 is: 3
the inverse factorial of 24 is: 4
the inverse factorial of 120 is: 5
the inverse factorial of 720 is: 6
the inverse factorial of 5040 is: 7
the inverse factorial of 40320 is: 8
the inverse factorial of 362880 is: 9
the inverse factorial of 3628800 is: 10
the inverse factorial of 119 is: undefined
</pre>
 
=={{header|Wren}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.