Last active
February 3, 2019 07:03
-
-
Save justinmeiners/e634a9cb385df347cf9142fd940ba735 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use srfi-1) | |
; partition(0) | |
; (null) | |
; partition(n) | |
; (n) + part(0) | |
; (n - 1) + part(1) | |
; (n - 2) + part(2) | |
; ... | |
; (1) + part(n - 1) | |
(define (partition-n n) | |
(define (iter k) | |
(if (= k n) | |
'() | |
(append | |
(map | |
(lambda (tail) (cons (- n k) tail)) | |
(filter (lambda (tail) | |
(or (null? tail) | |
(<= (car tail) (- n k)))) (partition-n k))) | |
(iter (+ k 1))))) | |
(if (= n 0) | |
(list '()) | |
(iter 0))) | |
(partition-n 4) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment