Left factorials: Difference between revisions
→{{header|Racket}}: tightened up a bit (especially the dnl's)
(=={{header|Racket}}== implementation added) |
(→{{header|Racket}}: tightened up a bit (especially the dnl's)) |
||
Line 346:
<lang racket>#lang racket
(define ! (let ((rv# (
▲ (lambda (n) (hash-ref! memo# n (lambda () (if (zero? n) 1(* n (! (sub1 n)))))))))
(define (!n n)
Line 354 ⟶ 352:
(for/sum ((k (in-range n))) (! k)))
(define
(dnl
▲(dln "Display the left factorials for:"
▲ "zero through ten (inclusive)")
▲(pretty-print (for/list ((i (in-range 0 (add1 10)))) (!n i)))
(pretty-
▲(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}}
|