Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

n C r

Name: Anonymous 2009-05-24 17:51

(define combination
  (λ(n k)
    (let ((stalled-factorial
           (λ(N stop-value)
             (define iter-sf
               (λ(accum N stop-value)
                 (if (= N stop-value)
                     accum
                     (iter-sf (* accum N) (- N 1) stop-value))))
             (iter-sf 1 N stop-value))))
      (if (> k (- n k))
          (/ (stalled-factorial n k) (factorial (- n k)))
          (/ (stalled-factorial n (- n k)) (factorial k))))))

Name: Anonymous 2009-05-24 19:06

>>1
Did you mean:
fact n = product [2..n]
perm n r = product [n-r+1..n]
comb n r = let sr = min r (n-r) in
    perm n sr `div` fact sr

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List