Left factorials: Difference between revisions
Content added Content deleted
ReeceGoding (talk | contribs) (→Vectorization solution: Removed need to check for n=0.) |
m (→{{header|REXX}}: simplfied code, added/change comments and whitespace, used a template for the output sections.) |
||
Line 3,057: | Line 3,057: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program |
<lang rexx>/*REXX program computes/display the left factorial (or its dec. width) of N (or a range)*/ |
||
parse arg bot top inc . /*obtain optional argumenst from the CL*/ |
parse arg bot top inc . /*obtain optional argumenst from the CL*/ |
||
if bot=='' | bot=="," then bot= |
if bot=='' | bot=="," then bot= 1 /*Not specified: Then use the default.*/ |
||
if top=='' | top=="," then top= |
if top=='' | top=="," then top= bot /* " " " " " " */ |
||
if inc='' | inc=="," then inc= |
if inc='' | inc=="," then inc= 1 /* " " " " " " */ |
||
tell= bot<0 /*if BOT < 0, only show # of digits. */ |
|||
bot=abs(bot) |
bot= abs(bot) /*use the │bot│ for the DO loop. */ |
||
w= length(top) /*width of the largest number request. */ |
|||
do j=bot to top by inc /*traipse through the numbers requested*/ |
|||
if tell then say 'left ! of ' right(j,w) " ───► " length(L!(j)) ' digits' |
|||
else say 'left ! of ' right(j,w) " ───► " L!(j) |
|||
end /*j*/ /* [↑] show either L! or # of digits*/ |
|||
exit 0 /*stick a fork in it, we're all done. */ |
|||
exit /*stick a fork in it, we're all done. */ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
L!: procedure; parse arg x .; if x<3 then return x; |
L!: procedure; parse arg x .; if x<3 then return x; $= 4; != 2 /*some shortcuts.*/ |
||
do #=3 to x-1; != ! * # /*compute L! for all numbers ─── ► X.*/ |
|||
if pos(., !)\==0 then numeric digits digits() * 3 % 2 /*bump dec. digs.*/ |
|||
$= $ + ! /*add the factorial ───► L! sum. */ |
|||
end /*#*/ /* [↑] handles gihugeic numbers. */ |
|||
return $ /*return the sum (L!) to the invoker.*/</lang> |
|||
⚫ | |||
return s /*return the sum (L!) to the invoker.*/</lang> |
|||
⚫ | |||
<pre> |
<pre> |
||
left ! of 0 ───► 0 |
left ! of 0 ───► 0 |
||
Line 3,093: | Line 3,091: | ||
left ! of 10 ───► 409114 |
left ! of 10 ───► 409114 |
||
</pre> |
</pre> |
||
{{out|output|text= when using the input of: <tt> 20 110 10 </tt>}} |
|||
<pre> |
<pre> |
||
left ! of 20 ───► 128425485935180314 |
left ! of 20 ───► 128425485935180314 |
||
Line 3,106: | Line 3,104: | ||
left ! of 110 ───► 145722981061585297004706728001906071948635199234860720988658042536179281328615541936083296163475394237524337422204397431927131629058103519228197429698252556442336528920420940314 |
left ! of 110 ───► 145722981061585297004706728001906071948635199234860720988658042536179281328615541936083296163475394237524337422204397431927131629058103519228197429698252556442336528920420940314 |
||
</pre> |
</pre> |
||
{{out|output|text= when using the input of: <tt> -1000 10000 1000 </tt>}} |
|||
<pre> |
<pre> |
||
left ! of 1000 ───► 2565 digits |
left ! of 1000 ───► 2565 digits |