24 lines
1.1 KiB
Scheme
24 lines
1.1 KiB
Scheme
(define (combinations n k)
|
|
(do ((i 0 (+ 1 i))
|
|
(res 1 (/ (* res (- n i))
|
|
(- k i))))
|
|
((= i k) res)))
|
|
|
|
(define (permutations n k)
|
|
(do ((i 0 (+ 1 i))
|
|
(res 1 (* res (- n i))))
|
|
((= i k) res)))
|
|
|
|
(display "P(4,2) = ") (display (permutations 4 2)) (newline)
|
|
(display "P(8,2) = ") (display (permutations 8 2)) (newline)
|
|
(display "P(10,8) = ") (display (permutations 10 8)) (newline)
|
|
(display "C(10,8) = ") (display (combinations 10 8)) (newline)
|
|
(display "C(20,8) = ") (display (combinations 20 8)) (newline)
|
|
(display "C(60,58) = ") (display (combinations 60 58)) (newline)
|
|
(display "P(1000,10) = ") (display (permutations 1000 10)) (newline)
|
|
(display "P(1000,20) = ") (display (permutations 1000 20)) (newline)
|
|
(display "P(15000,2) = ") (display (permutations 15000 3)) (newline)
|
|
(display "C(1000,10) = ") (display (combinations 1000 10)) (newline)
|
|
(display "C(1000,999) = ") (display (combinations 1000 999)) (newline)
|
|
(display "C(1000,1000) = ") (display (combinations 1000 1000)) (newline)
|
|
(display "C(15000,14998) = ") (display (combinations 15000 14998)) (newline)
|