Left factorials: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: Tidying) |
(Added Wren) |
||
Line 3,586: | Line 3,586: | ||
!9000 has 31678 digits |
!9000 has 31678 digits |
||
!10000 has 35656 digits |
!10000 has 35656 digits |
||
</pre> |
|||
=={{header|Wren}}== |
|||
<lang ecmascript>import "/fmt" for Fmt |
|||
import "/big" for BigInt |
|||
var lfacts = List.filled(12, BigInt.zero) |
|||
var lfact = BigInt.one |
|||
var sum = BigInt.zero |
|||
for (i in 1..10) { |
|||
sum = sum + lfact |
|||
lfacts[i] = sum |
|||
lfact = lfact * i |
|||
} |
|||
System.print("Left factorials from 0 to 10:") |
|||
for (i in 0..10) System.write(" %(lfacts[i])") |
|||
for (i in 11..110) { |
|||
sum = sum + lfact |
|||
if (i%10 == 0) lfacts[i/10] = sum |
|||
lfact = lfact * i |
|||
} |
|||
System.print("\n\nLeft factorials from 20 to 110 by tens:") |
|||
for (i in 2..11) Fmt.print(" !$-3d -> $s", i * 10, lfacts[i]) |
|||
for (i in 111..10000) { |
|||
sum = sum + lfact |
|||
if (i%1000 == 0) lfacts[i/1000] = sum |
|||
lfact = lfact * i |
|||
} |
|||
System.print("\nLengths of left factorals from 1000 to 10000 by thousands:") |
|||
for (i in 1..10) Fmt.print(" !$-5d -> $5s", i * 1000, lfacts[i].toString.count)</lang> |
|||
{{out}} |
|||
<pre> |
|||
Left factorials from 0 to 10: |
|||
0 1 2 4 10 34 154 874 5914 46234 409114 |
|||
Left factorials from 20 to 110 by tens: |
|||
!20 -> 128425485935180314 |
|||
!30 -> 9157958657951075573395300940314 |
|||
!40 -> 20935051082417771847631371547939998232420940314 |
|||
!50 -> 620960027832821612639424806694551108812720525606160920420940314 |
|||
!60 -> 141074930726669571000530822087000522211656242116439949000980378746128920420940314 |
|||
!70 -> 173639511802987526699717162409282876065556519849603157850853034644815111221599509216528920420940314 |
|||
!80 -> 906089587987695346534516804650290637694024830011956365184327674619752094289696314882008531991840922336528920420940314 |
|||
!90 -> 16695570072624210767034167688394623360733515163575864136345910335924039962404869510225723072235842668787507993136908442336528920420940314 |
|||
!100 -> 942786239765826579160595268206839381354754349601050974345395410407078230249590414458830117442618180732911203520208889371641659121356556442336528920420940314 |
|||
!110 -> 145722981061585297004706728001906071948635199234860720988658042536179281328615541936083296163475394237524337422204397431927131629058103519228197429698252556442336528920420940314 |
|||
Lengths of left factorals from 1000 to 10000 by thousands: |
|||
!1000 -> 2565 |
|||
!2000 -> 5733 |
|||
!3000 -> 9128 |
|||
!4000 -> 12670 |
|||
!5000 -> 16322 |
|||
!6000 -> 20062 |
|||
!7000 -> 23875 |
|||
!8000 -> 27749 |
|||
!9000 -> 31678 |
|||
!10000 -> 35656 |
|||
</pre> |
</pre> |
||