Skip to content

Instantly share code, notes, and snippets.

@b4284
Created January 27, 2016 05:38
Show Gist options
  • Select an option

  • Save b4284/3ff0bd6ccd6762098b30 to your computer and use it in GitHub Desktop.

Select an option

Save b4284/3ff0bd6ccd6762098b30 to your computer and use it in GitHub Desktop.
(use-modules (srfi srfi-1)
(ice-9 pretty-print))
(define (sum ls)
(if (null? ls)
0
(+ (car ls) (sum (cdr ls)))))
(define (sum2 ls)
(apply + ls))
(define* (integer-composition-by-sequence i #:optional (step 1) (beg 0))
(let B ((M `((,beg ,(+ beg step)))) (lsm (+ beg beg step)))
(if (null? (car M))
(cdr (reverse (cdr M)))
(let ((nal (drop (car M) 1)))
(let A ((al nal) (S (- lsm (caar M))))
(cond
((null? al) (B (cons '() M) S)) ;; No solution
((< S i)
(let* ((F (reverse al))
(Q (+ step (car F))))
(A (reverse (cons Q F)) (+ S Q))))
((> S i)
(A (cdr al) (- S (car al))))
((= S) (B (cons al M) S))))))))
(pretty-print
(filter
(lambda (l) (> (length (cdr l)) 1))
(map (lambda (x) (cons x (integer-composition-by-sequence 216 x)))
(iota 216 1))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment