From 4de900d8769fa687787464ba2cf2e050f0dfb399 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 3 Sep 2016 03:15:03 +0000 Subject: add one/twelve.scm made some progress on ex. 1.12. --- one/twelve.scm | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 one/twelve.scm diff --git a/one/twelve.scm b/one/twelve.scm new file mode 100644 index 0000000..39c3d8b --- /dev/null +++ b/one/twelve.scm @@ -0,0 +1,30 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; . + +;;; pascal's fucking triangle. + +(define-module (one twelve) + #:export (compute-triangle + compute-line + display-line + value-at)) + +(define (compute-triangle n) + (cond ((= n 1) (list (compute-line n 1))) + (else (cons (compute-line n 1) + (compute-triangle (- n 1)))))) + +(define (compute-line n pos) + (cond ((> pos n) '()) + (else + (cons (value-at n pos) + (compute-line n (+ pos 1)))))) + +(define (value-at line pos) + (cond ((= line 1) 1) + ((= pos 1) 1) + ((= line pos) 1) + (else (+ + (value-at (- line 1) (- pos 1)) + (value-at (- line 1) pos))))) -- cgit v1.2.3