Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun robot (x y k)
- (let ((n 100) (m 100) (x1 60) (y1 60))
- (if (= k 0)
- (if (and (= x x1) (= y y1)) 1 0)
- (let
- (
- (up (if (< (+ y 1) m) (robot x (+ y 1) (- k 1)) 0))
- (down (if (>= (- y 1) 0) (robot x (- y 1) (- k 1)) 0))
- (right (if (< (+ x 1) n) (robot (+ x 1) y (- k 1)) 0))
- (left (if (>= (- x 1) 0) (robot (- x 1) y (- k 1)) 0))
- )
- (+ up down right left)
- )
- )
- )
- )
- (defun memoize (fn)
- (let ((cache (make-hash-table :test #'equal)))
- #'(lambda (&rest args)
- (multiple-value-bind
- (result exists)
- (gethash args cache)
- (if exists
- result
- (setf (gethash args cache)
- (apply fn args)))))))
- (setf (fdefinition 'robot) (memoize #'robot))
- (print (robot 50 50 200))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement