Sunday, November 30, 2014

Project Euler Problem 16 Common Lisp

Project Euler Problem 16

(defun sum-digits (x &optional (sum 0))
  (multiple-value-bind (m n)
    (truncate x 10)
    (if (zerop m)
      (+ n sum)
      (sum-digits m (+ n sum)))))

(defun problem16 ()
  (sum-digits (expt 2 1000)))

No comments:

Post a Comment