p053.scm 558 B

123456789101112131415161718192021
  1. ;; Combinatoric selections
  2. (define-module (solved p053))
  3. (use-modules (euler math))
  4. (define (get-combinations>val-with-n min-val n)
  5. (filter (lambda (combination)
  6. (> combination min-val))
  7. (get-combinations n)))
  8. (define (get-combinations limit)
  9. (let generator ((n 1) (r 1) (combinations '()))
  10. (cond
  11. ((> n limit) combinations)
  12. ((> r n) (generator (1+ n) 1 combinations))
  13. (else (generator n (1+ r) (cons (combination n r) combinations))))))
  14. (define (combination n r)
  15. (/ (factorial n) (* (factorial r) (factorial (- n r)))))