diff options
author | rsiddharth <s@ricketyspace.net> | 2016-09-14 02:21:45 +0000 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2016-09-14 02:21:45 +0000 |
commit | 2c3ed4ccc0c8d81f8cca28dfb5f2cdf2daf29ddc (patch) | |
tree | ba2e132d5d61f6bc0bcd0065002bf92bd5577a26 /one | |
parent | 4de900d8769fa687787464ba2cf2e050f0dfb399 (diff) |
one/twelve.scm: add printing functions
They work only when all values of the triangle are single digit.
Diffstat (limited to 'one')
-rw-r--r-- | one/twelve.scm | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/one/twelve.scm b/one/twelve.scm index 39c3d8b..1e201dc 100644 --- a/one/twelve.scm +++ b/one/twelve.scm @@ -8,7 +8,9 @@ #:export (compute-triangle compute-line display-line - value-at)) + value-at + print-triangle + print-line)) (define (compute-triangle n) (cond ((= n 1) (list (compute-line n 1))) @@ -28,3 +30,17 @@ (else (+ (value-at (- line 1) (- pos 1)) (value-at (- line 1) pos))))) + +;;;; printing + +(define (print-triangle tl level) + (cond ((= (length tl) 0) #t) + (else + (print-triangle (cdr tl) (+ 1 level)) + (print-line (car tl) level)))) + +(define (print-line l level) + (let* ((l (map number->string l)) + (spaces (string-join (make-list level " ") "")) + (line (string-append spaces (string-join l)))) + (format #t "~a\n" line))) |