Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun digits (n &optional (b 10))
- (loop for i = n then (floor i b) with lst = ()
- do (push (mod i b) lst)
- while (> i (1- b))
- finally (return lst)))
- (defun onep (n) (equal 1 n))
- (defun count-ones (n)
- (reduce #'+ (remove-if-not #'onep (digits n))))
Add Comment
Please, Sign In to add comment