combinations   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/runtime/scheme.xtm

Implementation

;; return all combinations of set
;; of subsets (size of set)
(define combinations
  (lambda (s size)
     (if (= 0 size) '()
  (flatten-1 (map (lambda (x)
         (let ((res (combinations (list-tail s (+ 1 (cl:position x s))) (- size 1))))
            (if (null? res) (list x)
          (map (lambda (y)
            (if (list? y) (list* x y) (list x y)))
               (flatten-1 res)))))
      (list-head s (- (length s) ( - size 1))))))))


Back to Index

Similar Entries

  • combinations    scheme