4 [else (drop (- n 1) (cdr xs))]))
6 (define (drop-end n xs)
7 (reverse (drop n (reverse xs))))
11 (append (range s (- n 1))
12 (list (+ s (- n 1))))))
14 (define (flat-map f . xs) (fold-left append '() (apply map (cons f xs))))
15 (define (repeat x n) (if (<= n 0) '()
16 (cons x (repeat x (- n 1)))))
21 ((_ s x) (set! s (cons x s)))))
25 ((_ s) (let ([x (car s)])
31 (lambda (acc y) (if acc #t (p y)))
35 (define (all xs) (fold-left (lambda (acc x) (and acc x)) #t xs))
37 ; (combinations '(1 2) '(3)) => '((1 3) (2 3))
38 (define (combinations . lists)
41 [1 (map (lambda (x) (list x)) (car lists))]
42 [else (flat-map (lambda (x)
43 (map (lambda (y) (cons x y))
44 (apply combinations (cdr lists)))) (car lists))]))