Left factorials: Difference between revisions

=={{header|Racket}}== implementation added
(=={{header|Racket}}== stub added)
(=={{header|Racket}}== implementation added)
Line 345:
=={{header|Racket}}==
 
<lang racket>#lang racket
(define !
</lang>
(let ((memo# (make-hash)))
(lambda (n) (hash-ref! memo# n (lambda () (if (zero? n) 1(* n (! (sub1 n)))))))))
 
(define (!n n)
;; note that in-range n is from 0 to n-1 inclusive
(for/sum ((k (in-range n))) (! k)))
 
(define !n-digits (compose add1 order-of-magnitude !n))
 
(define (dln . s)
(for-each displayln s))
 
(dln "Display the left factorials for:"
"zero through ten (inclusive)")
(pretty-print (for/list ((i (in-range 0 (add1 10)))) (!n i)))
 
(dln "20 through 110 (inclusive) by tens")
(pretty-print (for/list ((i (in-range 20 (add1 110) 10))) (!n i)))
 
(dln "Display the length (in decimal digits) of the left factorials for:"
"1,000, 2,000 through 10,000 (inclusive), by thousands.")
(pretty-print (for/list ((!i-len (sequence-map !n-digits (in-range 1000 10001 1000)))) !i-len))</lang>
 
{{out}}
<pre>Display the left factorials for:
<pre>
zero through ten (inclusive)
</pre>
'(0 1 2 4 10 34 154 874 5914 46234 409114)
20 through 110 (inclusive) by tens
'(128425485935180314
9157958657951075573395300940314
20935051082417771847631371547939998232420940314
620960027832821612639424806694551108812720525606160920420940314
141074930726669571000530822087000522211656242116439949000980378746128920420940314
173639511802987526699717162409282876065556519849603157850853034644815111221599509216528920420940314
906089587987695346534516804650290637694024830011956365184327674619752094289696314882008531991840922336528920420940314
16695570072624210767034167688394623360733515163575864136345910335924039962404869510225723072235842668787507993136908442336528920420940314
942786239765826579160595268206839381354754349601050974345395410407078230249590414458830117442618180732911203520208889371641659121356556442336528920420940314
145722981061585297004706728001906071948635199234860720988658042536179281328615541936083296163475394237524337422204397431927131629058103519228197429698252556442336528920420940314)
Display the length (in decimal digits) of the left factorials for:
1,000, 2,000 through 10,000 (inclusive), by thousands.
'(2565 5733 9128 12670 16322 20062 23875 27749 31678 35656)</pre>
 
=={{header|REXX}}==
569

edits