l-99

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

commit 2933399663d5ae36c6ea67d9e2f1185d8dbde328
parent 9e19d6008110c25856cdc57cfba5c6231034dba1
Author: Jenny Doe <tng@soykaf.me>
Date:   Mon,  8 Apr 2019 16:16:21 +0200

added: p18.scm

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

diff --git a/p18.scm b/p18.scm @@ -0,0 +1,18 @@ +; (**) Extract a slice from a list. +; Given two indices, I and K, the slice is the list containing the +; elements between the I'th and K'th element of the original list (both +; limits included). Start counting the elements with 1. +; +; Example: +; * (slice '(a b c d e f g h i k) 3 7) +; (C D E F G) + +(define (slice ls n m) + (cond + ((null? ls) '()) + ((zero? m) '()) + ((= 1 n) + (cons (car ls) + (slice (cdr ls) 1 (- m 1)))) + (else + (slice (cdr ls) (- n 1) (- m 1)))))