Advertisement
Guest User

homework binoms

a guest
May 26th, 2012
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.67 KB | None | 0 0
  1. (defun factorial (n)
  2.   (let ((result 1))
  3.     (dotimes (i n result)
  4.       (setf result (* result (1+ i))))))
  5.  
  6. (defun combinations (m n)
  7.   (/ (factorial m) (* (factorial n) (factorial (- m n)))))
  8.  
  9. (defun harmonic (n)
  10.   (let ((result 0))
  11.     (dotimes (i n result)
  12.       (incf result
  13.         (* (expt -1 i) (/ 1 (1+ i))
  14.            (combinations n (1+ i)))))))
  15.  
  16. (defun question-1 (m)
  17.   (let ((result 0))
  18.     (dotimes (n (1+ m) result)
  19.       (incf result
  20.         (* (/ 1 (+ n 1)) (combinations m n))))))
  21.  
  22. (defun question-1-2 (m)
  23.   (let ((result 0))
  24.     (dotimes (n (1+ m) result)
  25.       (incf result
  26.         (/ (factorial m)
  27.            (* (factorial (1+ n)) (factorial (- m n))))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement