diff options
author | Julian T <julian@jtle.dk> | 2021-09-08 12:43:04 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-09-08 12:43:04 +0200 |
commit | 8fe80b1bfe70267b29bb39ccb93f24fdd94847fc (patch) | |
tree | 47e438407dc80dc7e560cb97c3666e97a1910178 /sem7/pp/lec1/exercises.sch | |
parent | c03ad645b32d191dd5aa8c2f492f8067f351d137 (diff) |
Rename to better scheme extension
Diffstat (limited to 'sem7/pp/lec1/exercises.sch')
-rw-r--r-- | sem7/pp/lec1/exercises.sch | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/sem7/pp/lec1/exercises.sch b/sem7/pp/lec1/exercises.sch deleted file mode 100644 index 9be35e2..0000000 --- a/sem7/pp/lec1/exercises.sch +++ /dev/null @@ -1,36 +0,0 @@ -(define (make-list-ft from to) - (if (> from to) - '() - (cons from (make-list-ft (1+ from) to)))) - -;; Exercise 1.3 (proper lists) -;;? Program own version of list?, thus proper-list? -;; This is done by running to the end of list, always checking if pair. -;; If last element is '() its a proper list, otherwize its not. -(define (proper-list? list) - (if (pair? list) - (proper-list? (cdr list)) - (null? list))) - -;;? Can you write your predicate without using if or cond? -;; Hmm i cant see how this would be done, as we are using recursion which requires a stop condition. - -;;? Is your function efficient? What is the time complexity? -;; This runs over all the elements in the list, so O(n). -;; Hmm reading through the solution, i see that we can use other conditional functions like `or` and `and`. -;; Lets try that -(define (proper-list? list) - (or (null? list) (and (pair? list) (proper-list? (cdr list))))) - -;; Okay thats just his solution - -;; Exercise 1.5 (every second element) -;; Hmm the text mentions that we could write it with (every-nth-element) -(define (every-nth-element n list) - (let recur ((list list) (index 0)) - (cond ((null? list) '()) - ((zero? (modulo index n)) (cons (car list) (recur (cdr list) (1+ index)))) - (else (recur (cdr list) (1+ index)))))) - -(define (every-2th-element list) - (every-nth-element 2 list)) |