#lang racket
;(define (f lst)
; (let loop ((a (car lst)) (b (cadr lst)) (lst (cddr lst)) (acc '()))
; (if (null? lst)
; (cons (+ a b) acc)
; (loop b (car lst) (cdr lst) (cons (+ a b) acc)))))
;
;(define (pascal n)
; (let loop ((n n) (acc '((1) (1 1))))
; (cond ((zero? n) `(,(car acc)))
; ((= n 1) acc)
; (else (loop (- n 1) `(,@acc (1 ,@(f (last acc)) 1)))))))
;;; 別解
(define (pascal n)
(foldl (lambda (y x)
(cond ((zero? y) x)
((= y 1) `(,@x (,y ,y)))
(else `(,@x (1 ,@(let ((lst (last x)))
(map + (take lst (- (length lst) 1))
(cdr lst))) 1)))))
'((1)) (range 0 (+ n 1))))
I2xhbmcgcmFja2V0CiAKOyhkZWZpbmUgKGYgbHN0KQo7ICAobGV0IGxvb3AgKChhIChjYXIgbHN0KSkgKGIgKGNhZHIgbHN0KSkgKGxzdCAoY2RkciBsc3QpKSAoYWNjICcoKSkpCjsgICAgKGlmIChudWxsPyBsc3QpCjsgICAgICAgIChjb25zICgrIGEgYikgYWNjKQo7ICAgICAgICAobG9vcCBiIChjYXIgbHN0KSAoY2RyIGxzdCkgKGNvbnMgKCsgYSBiKSBhY2MpKSkpKQo7CjsoZGVmaW5lIChwYXNjYWwgbikKOyAgKGxldCBsb29wICgobiBuKSAoYWNjICcoKDEpICgxIDEpKSkpCjsgICAgKGNvbmQgKCh6ZXJvPyBuKSBgKCwoY2FyIGFjYykpKQo7ICAgICAgICAgICgoPSBuIDEpIGFjYykKOyAgICAgICAgICAoZWxzZSAobG9vcCAoLSBuIDEpIGAoLEBhY2MgKDEgLEAoZiAobGFzdCBhY2MpKSAxKSkpKSkpKQogCjs7OyDliKXop6MKCihkZWZpbmUgKHBhc2NhbCBuKQogIChmb2xkbCAobGFtYmRhICh5IHgpCiAgICAgICAgICAgKGNvbmQgKCh6ZXJvPyB5KSB4KQogICAgICAgICAgICAgICAgICgoPSB5IDEpIGAoLEB4ICgseSAseSkpKQogICAgICAgICAgICAgICAgIChlbHNlIGAoLEB4ICgxICxAKGxldCAoKGxzdCAobGFzdCB4KSkpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChtYXAgKyAodGFrZSBsc3QgKC0gKGxlbmd0aCBsc3QpIDEpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChjZHIgbHN0KSkpIDEpKSkpKQogICAgICAgICAnKCgxKSkgKHJhbmdlIDAgKCsgbiAxKSkpKQ==