Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

http://programmingpraxis.com/2012/06/15/counting-ones/

By: a guest on Jun 15th, 2012  |  syntax: Lisp  |  size: 0.27 KB  |  views: 46  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (defun digits (n &optional (b 10))
  2.   (loop for i = n then (floor i b) with lst = ()
  3.      do (push (mod i b) lst)
  4.      while (> i (1- b))
  5.      finally (return lst)))
  6.  
  7. (defun onep (n) (equal 1 n))
  8. (defun count-ones (n)
  9.   (reduce #'+ (remove-if-not #'onep (digits n))))