SHARE
TWEET

Untitled

a guest Nov 13th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. (use-syntax (ice-9 syncase))
  3. (define memoized-factorial
  4.   (let ((memo '()))
  5.     (lambda (n)
  6.       (let ((memoized (assq n memo)))
  7.         (if (not (equal? memoized #f))
  8.             (cadr memoized)
  9.             (let ((new-value
  10.                    (if (< n 1)
  11.                        1
  12.                        (* n (memoized-factorial (- n 1))))))
  13.               (set! memo (cons (list n new-value) memo))
  14.               new-value))))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top