Welcome to the CHICKEN Scheme pasting service

count set bits added by mario-goulart on Sun Sep 11 09:11:42 2016

(define (count-set-bits n)
  (let loop ((n n)
             (set-bits 0))
    (if (zero? n)
        set-bits
        (loop (bitwise-and n (fx- n 1))
              (fx+ set-bits 1)))))

(let loop ((n 0))
  (when (< n 16)
    (print "n=" n "  set bits=" (count-set-bits n))
    (loop (+ n 1))))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What's the one-argument procedure to check if a list is empty?
Visually impaired? Let me spell it for you (wav file) download WAV