Left factorials: Difference between revisions

Content added Content deleted
(→‎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 computes/display the left factorial (or its width) of N (or range). */
<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= 1 /*Not specified: Then use the default.*/
if bot=='' | bot=="," then bot= 1 /*Not specified: Then use the default.*/
if top=='' | top=="," then top=bot /* " " " " " " */
if top=='' | top=="," then top= bot /* " " " " " " */
if inc='' | inc=="," then inc= 1 /* " " " " " " */
if inc='' | inc=="," then inc= 1 /* " " " " " " */
tellDigs= (bot<0) /*if BOT < 0, only show # of digits. */
tell= bot<0 /*if BOT < 0, only show # of digits. */
bot=abs(bot) /*use the │bot│ for the DO loop. */
bot= abs(bot) /*use the │bot│ for the DO loop. */
@= 'left ! of ' /*a handy literal used in the display. */
w= length(top) /*width of the largest number request. */
w=length(H) /*width of the largest number request. */
do j=bot to top by inc /*traipse through the numbers requested*/
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'
if tellDigs then say @ right(j,w) " ───► " length(L!(j)) ' digits'
else say 'left ! of ' right(j,w) " ───► " L!(j)
else say @ right(j,w) " ───► " L!(j)
end /*j*/ /* [↑] show either L! or # of digits*/
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; s=4 /*some shortcuts. */
L!: procedure; parse arg x .; if x<3 then return x; $= 4; != 2 /*some shortcuts.*/
!=2; do f=3 to x-1 /*compute L! for all numbers ─── ► X.*/
do #=3 to x-1; != ! * # /*compute L! for all numbers ─── ► X.*/
!=!*f /*compute intermediate factorial. */
if pos(., !)\==0 then numeric digits digits() * 3 % 2 /*bump dec. digs.*/
if pos(.,!)\==0 then numeric digits digits()*1.5%1 /*bump decimal digits.*/
$= $ + ! /*add the factorial ───► L! sum. */
s=s+! /*add the factorial ───► L! sum. */
end /*#*/ /* [↑] handles gihugeic numbers. */
end /*f*/ /* [↑] handles gihugeic numbers. */
return $ /*return the sum (L!) to the invoker.*/</lang>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 0 &nbsp; 10 </tt>}}
return s /*return the sum (L!) to the invoker.*/</lang>
'''output''' &nbsp; when using the input: &nbsp; <tt> 0 &nbsp; 10 </tt>
<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>
'''output''' &nbsp; when using the input: &nbsp; <tt> 20 &nbsp; 110 &nbsp; 10 </tt>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; &nbsp; <tt> 20 &nbsp; 110 &nbsp; 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>
'''output''' &nbsp; when using the input: &nbsp; <tt> -1000 &nbsp; 10000 &nbsp; 1000 </tt>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> -1000 &nbsp; 10000 &nbsp; 1000 </tt>}}
<pre>
<pre>
left ! of 1000 ───► 2565 digits
left ! of 1000 ───► 2565 digits