Skip to content

Instantly share code, notes, and snippets.

@honix
Last active October 31, 2016 12:36
Show Gist options
  • Save honix/d1b9e60e4de5add1a242309ef5456f10 to your computer and use it in GitHub Desktop.
Save honix/d1b9e60e4de5add1a242309ef5456f10 to your computer and use it in GitHub Desktop.
(defun weak-tripo (n)
(case n
(0 0)
(1 0)
(2 1)
(t (+ (weak-tripo (- n 1))
(weak-tripo (- n 2))
(weak-tripo (- n 3))))))
(let ((table (make-hash-table)))
(defun super-tripo (n)
(or (gethash n table)
(setf (gethash n table)
(case n
(0 0)
(1 0)
(2 1)
(t (+ (super-tripo (- n 1))
(super-tripo (- n 2))
(super-tripo (- n 3)))))))))
(time (weak-tripo 35)) ; 10 sec
(time (super-tripo 1000)) ; 0 sec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment