-
Notifications
You must be signed in to change notification settings - Fork 0
/
codeToRun.txt
18 lines (18 loc) · 1.25 KB
/
codeToRun.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(define (length L) (if (equal? L empty) 0 (if (not (equal? L empty)) (+ 1 (length (cdr L))) )))
(define (nth n L) (if ((lambda (x y) (if x y #f)) (equal? n 1) (> (length L) 0)) (car L) (if ((lambda (x y) (if x y #f)) (<= 1 n) (<= n (length L))) (nth (- n 1) (cdr L)) )))
(define (count x L) (if (equal? L empty) 0 (if (equal? (car L) x) (+ 1 (count x (cdr L))) (if (not (equal? (car L) x)) (count x (cdr L)) ))))
(define (sorted L) (if (equal? L empty) #t (if (equal? (length L) 1) #t (if (>= (length L) 2) ((lambda (x y) (if x y #f)) (<= (car L) (car (cdr L))) (sorted (cdr L))) ))))
(define (reverse L) (if (equal? L empty) empty (if (not (equal? L empty)) (append (reverse (cdr L)) (cons (car L) empty)) )))
(define (in x L) (if (equal? L empty) (not #t) (> (count x L) 0) ))
(define (min L) (if (equal? (length L) 1) (car L) (if ((lambda (x y) (if x y #f)) (> (length L) 1) (<= (car L) (car (cdr L)))) (min (cons (car L) (cdr (cdr L)))) (if ((lambda (x y) (if x y #f)) (> (length L) 1) (> (car L) (car (cdr L)))) (min (cdr L)) ))))
(define list1 0) (set! list1 (list 2 2 3 4 5 6 7 8 9))
(define list2 0) (set! list2 (list 22 22 22 22 22 22 3 4))
(length list1)
(nth 2 list2)
(count 22 list2)
(sorted list1)
(sorted list2)
(reverse list1)
(in 10 list1)
(in 9 list1)
(min list2)