l-99

solutions to l-99 (slow)
Log | Files | Refs | Feed

commit a74c391ec79bbdf556d07cda862fa9349eb84aaf
parent 4ecab87f432c705b30e3ef2cd0bf5bc15994d9d2
Author: Jenny Doe <tng@soykaf.me>
Date:   Sun, 24 Mar 2019 15:03:49 +0100

added: p12.scm

Diffstat:
Ap12.scm | 19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/p12.scm b/p12.scm @@ -0,0 +1,19 @@ +; (**) Decode a run-length encoded list. +; Given a run-length code list generated as specified in problem P11. +; Construct its uncompressed version. +; +; developer's notes: +; - works on both p10's and p11's output + +(define (widen a n) + (if (zero? n) + '() + (cons a (widen a (- n 1))))) + +(define (decode lat) + (if (null? lat) + '() + (if (pair? (car lat)) + (append (widen (cdar lat) (caar lat)) + (decode (cdr lat))) + (cons (car lat) (decode (cdr lat))))))