Skip to content

Commit

Permalink
test: scheme tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Leslie-Jiang-Hamster committed Jan 22, 2024
1 parent 78c22ad commit 9a16203
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions questions.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@

;; Problem 15
;; Returns a list of two-element lists
(define (iota n)
(if (= n 0) '() (append (iota (- n 1)) `(,(- n 1)))))

(define (zip_ seq1 seq2)
(if (null? seq1) '() (cons `(,(car seq1) ,(car seq2)) (zip_ (cdr seq1) (cdr seq2)))))

(define (enumerate s)
; BEGIN PROBLEM 15
'replace-this-line
)
(zip_ (iota (length s)) s))
; END PROBLEM 15

;; Problem 16
Expand All @@ -17,8 +22,10 @@
;; the merged lists.
(define (merge ordered? s1 s2)
; BEGIN PROBLEM 16
'replace-this-line
)
(cond ((null? s1) s2)
((null? s2) s1)
((ordered? (car s1) (car s2)) (cons (car s1) (merge ordered? (cdr s1) s2)))
(else (cons (car s2) (merge ordered? s1 (cdr s2))))))
; END PROBLEM 16

;; Optional Problem 2
Expand Down

0 comments on commit 9a16203

Please sign in to comment.