/usr/lib/s9fes/make-partitions.scm is in scheme9 2010.11.13-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | ; Scheme 9 from Empty Space, Function Library
; By Nils M Holm, 2009
; See the LICENSE file of the S9fES package for terms of use
;
; (make-partitions integer) ==> list
;
; Create all partitions of a positive integer. A (number-theoretical)
; partition of a positive integer N is a set of integers whose sum is
; equal to N. E.g., the partitions of 3 are 3, 2+1, and 1+1+1.
;
; Example: (make-partitions 4) ==> ((4) (3 1) (2 2) (2 1 1) (1 1 1 1))
(load-from-library "iota.scm")
(load-from-library "filter.scm")
(define (make-partitions n)
(letrec
((partition
(lambda (n)
(cond ((zero? n) '(()))
((= n 1) '((1)))
(else (apply append
(map (lambda (x)
(map (lambda (p)
(cons x p))
(partition (- n x))))
(iota 1 n)))))))
(filter-descending
(lambda (x)
(filter (lambda (p)
(or (null? p)
(null? (cdr p))
(apply >= p)))
x))))
(reverse! (filter-descending (partition n)))))
|