l-99

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

commit 7affc18246ac28b2ed759cf03d8941d2a944f4b7
parent a74c391ec79bbdf556d07cda862fa9349eb84aaf
Author: Jenny Doe <tng@soykaf.me>
Date:   Sun, 24 Mar 2019 15:09:40 +0100

added: p14.scm p15.scm

Diffstat:
Ap14.scm | 11+++++++++++
Ap15.scm | 15+++++++++++++++
2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/p14.scm b/p14.scm @@ -0,0 +1,11 @@ +; (*) Duplicate the elements of a list. +; Example: +; * (dupli '(a b c c d)) +; (A A B B C C C C D D) + +(define (dupli ls) + (if (null? ls) + '() + (cons (car ls) + (cons (car ls) + (dupli (cdr ls)))))) diff --git a/p15.scm b/p15.scm @@ -0,0 +1,15 @@ +; (**) Replicate the elements of a list a given number of times. +; Example: +; * (repli '(a b c) 3) +; (A A A B B B C C C) + +(define (make-list a n) + (if (zero? n) + '() + (cons a (make-list a (- n 1))))) + +(define (repli ls n) + (if (null? ls) + '() + (append (make-list (car ls) n) + (repli (cdr ls) n))))