Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,27 @@
|
|||
(defparameter *mm* (make-hash-table :test #'equal))
|
||||
|
||||
;;; generic memoization macro
|
||||
(defmacro defun-memoize (f (&rest args) &body body)
|
||||
(defmacro hash () `(gethash (cons ',f (list ,@args)) *mm*))
|
||||
(let ((h (gensym)))
|
||||
`(defun ,f (,@args)
|
||||
(let ((,h (hash)))
|
||||
(if ,h ,h
|
||||
(setf (hash) (progn ,@body)))))))
|
||||
|
||||
;;; def q
|
||||
(defun-memoize q (n)
|
||||
(if (<= n 2) 1
|
||||
(+ (q (- n (q (- n 1))))
|
||||
(q (- n (q (- n 2)))))))
|
||||
|
||||
;;; test
|
||||
(format t "First of Q: ~a~%Q(1000): ~a~%Bumps up to 100000: ~a~%"
|
||||
(loop for i from 1 to 10 collect (q i))
|
||||
(q 1000)
|
||||
(loop with c = 0 with last-q = (q 1)
|
||||
for i from 2 to 100000
|
||||
do (let ((next-q (q i)))
|
||||
(if (< next-q last-q) (incf c))
|
||||
(setf last-q next-q))
|
||||
finally (return c)))
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
(let ((cc (make-array 3 :element-type 'integer
|
||||
:initial-element 1
|
||||
:adjustable t
|
||||
:fill-pointer 3)))
|
||||
(defun q (n)
|
||||
(when (>= n (length cc))
|
||||
(loop for i from (length cc) below n do (q i))
|
||||
(vector-push-extend
|
||||
(+ (aref cc (- n (aref cc (- n 1))))
|
||||
(aref cc (- n (aref cc (- n 2)))))
|
||||
cc))
|
||||
(aref cc n)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue