Left factorials: Difference between revisions

m
(added Arturo)
m (→‎{{header|Wren}}: Minor tidy)
 
(5 intermediate revisions by 3 users not shown)
Line 1,610:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Left_factorials}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation —i.e. XML, JSON— they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
The following function calculates the left factorial directly by its definition:
In '''[https://formulae.org/?example=Left_factorials this]''' page you can see the program(s) related to this task and their results.
 
[[File:Fōrmulæ - Left factorials 08.png]]
 
However, the following is much faster:
 
[[File:Fōrmulæ - Left factorials 01.png]]
 
'''Test case 1. Showing left factorials from zero to ten'''
 
[[File:Fōrmulæ - Left factorials 02.png]]
 
[[File:Fōrmulæ - Left factorials 03.png]]
 
'''Test case 2. Showing left factorials from 20 to 110, by tens'''
 
[[File:Fōrmulæ - Left factorials 04.png]]
 
[[File:Fōrmulæ - Left factorials 05.png|858px]]
 
'''Test case 3. Showing length of left factorials, from 1,000 to 10,000 by thousands'''
 
[[File:Fōrmulæ - Left factorials 06.png]]
 
[[File:Fōrmulæ - Left factorials 07.png]]
 
=={{header|Frink}}==
Line 2,295 ⟶ 2,319:
31678
35656</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
l_factorial(n):=sum(k!,k,0,n-1)$
 
/* Test cases */
makelist(l_factorial(i),i,0,10);
 
makelist(l_factorial(i),i,20,110,10);
</syntaxhighlight>
{{out}}
<pre>
[0,1,2,4,10,34,154,874,5914,46234,409114]
 
[128425485935180314,9157958657951075573395300940314,20935051082417771847631371547939998232420940314,620960027832821612639424806694551108812720525606160920420940314,141074930726669571000530822087000522211656242116439949000980378746128920420940314,173639511802987526699717162409282876065556519849603157850853034644815111221599509216528920420940314,906089587987695346534516804650290637694024830011956365184327674619752094289696314882008531991840922336528920420940314,16695570072624210767034167688394623360733515163575864136345910335924039962404869510225723072235842668787507993136908442336528920420940314,942786239765826579160595268206839381354754349601050974345395410407078230249590414458830117442618180732911203520208889371641659121356556442336528920420940314,145722981061585297004706728001906071948635199234860720988658042536179281328615541936083296163475394237524337422204397431927131629058103519228197429698252556442336528920420940314]
</pre>
 
=={{header|Nim}}==
Line 3,244 ⟶ 3,284:
next
</syntaxhighlight>
 
=={{header|RPL}}==
For small values of n, the built-in number type can support the job:
≪ '''IF''' DUP '''THEN''' 0 1 ROT 1 - '''FOR''' k k FACT + '''NEXT END''' ≫ ‘<span style="color:blue">LFACT</span>’ STO
≪ { } 0 10 '''FOR''' n n <span style="color:blue">LFACT</span> + '''NEXT''' ≫ EVAL
 
'''Output:'''
1: { 0 1 2 4 10 34 154 874 5914 46234 409114 }
For 20 through 110 (inclusive) by tens, we need a kind of BigInt library if using a RPL version from the previous century. <code>ADDbig</code> and <code>MULbig</code> are defined at [[Long multiplication#RPL|Long multiplication]].
Calculation is optimized by using the recursive formula: <code>!(n+1) = !n * n + 1</code>
≪ "1" SWAP
'''WHILE''' DUP 1 > '''REPEAT'''
1 - DUP →STR ROT <span style="color:blue">MULbig</span> "1" <span style="color:blue"><span style="color:blue">ADDbig</span></span> SWAP
'''END''' DROP
≫ ‘<span style="color:blue">LFACTbig</span>’ STO
≪ 20 110 '''FOR''' n n <span style="color:blue">LFACTbig</span> 10 '''STEP''' ≫ EVAL
{{out}}
<pre>
10: "128425485935180314"
9: "9157958657951075573395300940314"
8: "20935051082417771847631371547939998232420940314"
7: "620960027832821612639424806694551108812720525606160920420940314"
6: "141074930726669571000530822087000522211656242116439949000980378746128920420940314"
5: "173639511802987526699717162409282876065556519849603157850853034644815111221599509216528920420940314"
4: "906089587987695346534516804650290637694024830011956365184327674619752094289696314882008531991840922336528920420940314"
3: "16695570072624210767034167688394623360733515163575864136345910335924039962404869510225723072235842668787507993136908442336528920420940314"
2: "942786239765826579160595268206839381354754349601050974345395410407078230249590414458830117442618180732911203520208889371641659121356556442336528920420940314"
1: "145722981061585297004706728001906071948635199234860720988658042536179281328615541936083296163475394237524337422204397431927131629058103519228197429698252556442336528920420940314"
</pre>
 
=={{header|Ruby}}==
Line 4,034 ⟶ 4,105:
{{libheader|Wren-fmt}}
{{libheader|Wren-big}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
import "./big" for BigInt
 
var lfacts = List.filled(12, BigInt.zero)
9,486

edits