Last active
October 31, 2016 12:36
-
-
Save honix/d1b9e60e4de5add1a242309ef5456f10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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