sicp

sicp sandbox.
git clone git://git.ricketyspace.net/sicp.git
Log | Files | Refs

commit 4de900d8769fa687787464ba2cf2e050f0dfb399
parent 11ea72350f581ea316d5a45b39958a030b40dd7e
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat,  3 Sep 2016 03:15:03 +0000

add one/twelve.scm

made some progress on ex. 1.12.

Diffstat:
one/twelve.scm | 30++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+), 0 deletions(-)

diff --git a/one/twelve.scm b/one/twelve.scm @@ -0,0 +1,30 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; <https://creativecommons.org/licenses/by-sa/4.0/>. + +;;; 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)))))