December 21, 2008
at
Sunday, December 21, 2008
Labels:
Computer Science,
Lisp,
Project Euler
Posted by
Billy
2^(15) = 32768 and the sum of its digits is
3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^(1000)?
(defun add-digits (num)
"Returns the sum of the number's digits"
(let ((sum 0)
(num-string (write-to-string num)))
(dotimes (i (length num-string))
(setf sum (+ sum (digit-char-p (schar num-string i)))))
sum))
(defun euler-16 ()
(add-digits (expt 2 1000)))
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment