• + 0 comments

    I have reached the next solution in common lisp, but the last test keeps failing with wrong result. I cannot undestand why, I have tested locally and the result seems to be the expected, and the performance is also good. Can anyone explain me what is the problem?

    (defun sumpent (n) (if (< n 2) 1 (+ (memopent (1- n)) (- (* 3 n) 2))))

    (let ((npast (make-hash-table))) (defun memopent (n) (let ((currval (gethash n npast))) (if currval currval (setf (gethash n npast) (sumpent n))))))

    (let ((n (read))) (loop for line from 0 below n do (format t "~a~%" (memopent (read)))))