-
Notifications
You must be signed in to change notification settings - Fork 0
/
vmin.scm
51 lines (46 loc) · 897 Bytes
/
vmin.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(define vmin
(lambda (l)
(if (null? (cdr l))
(car l)
(if (< (car l) (vmin (cdr l)))
(car l)
(vmin (cdr l))
)
)
)
)
; (vmin '(8 2 67 1 9))
(define sum
(lambda (l)
(if (null? l)
0
(+ (car l) (sum (cdr l)))
)
)
)
; (sum '(1 2 3))
(define sumepart
(lambda (l t s)
(if (null? (cdr l))
(append s (list (+ t (car l))))
(if (= t 0)
(sumepart (cdr l) (car l) s)
(sumepart (cdr l) 0 (append s (list (+ t (car l))) ))
)
)
)
)
(define sume
(lambda (l s)
(if (null? l)
'()
(if (null? (cdr l))
s
(sume (sumepart l 0 '()) (append s (sumepart l 0 '())))
)
)
)
)
;(sumepart '(1 2 3 4 5) 0 '())
;(sumepart '(1 2) 0 '())
(sume '(1 2 3 4 5) '())