[ create a new paste ] login | about

Link: http://codepad.org/uNQ5qsvJ    [ raw code | output | fork ]

programmingpraxis - Scheme, pasted on Sep 22:
1
2
3
4
5
6
7
8
9
10
11
12
; triangle roll-up

(define (but-last xs) (reverse (cdr (reverse xs))))

(define (pair-wise f xs) (map f (but-last xs) (cdr xs)))

(define (roll-up xs)
  (when (pair? xs)
    (roll-up (pair-wise + xs))
    (display xs) (newline)))

(roll-up '(4 7 3 6 7))


Output:
1
2
3
4
5
(81)
(40 41)
(21 19 22)
(11 10 9 13)
(4 7 3 6 7)


Create a new paste based on this one


Comments: