-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.txt
43 lines (35 loc) · 808 Bytes
/
1.txt
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
#lang scheme/base
;------------------------------- a
(define (2n-1!-list-a n)
(if (<= n 0)
'()
(let loop ((i 1) (result 1) (arr '()))
(cond ( (and (<= i (+ n 1)) (even? i)) (loop (+ i 1) (* i result) (cons result arr)))
( (and (<= i (+ n 1)) (not(even? i))) (loop (+ i 1) (* i result) arr))
(else (reverse arr))
)
)
)
)
;-------------------------------b
(define (factorial n)
(if (= n 0)
1
(* n (factorial (- n 1)))
)
)
(define (factlist n)
(if (<= n 0)
'()
(cons (factorial n) (factlist(- n 2)))
)
)
(define (2n-1!-list-b n)
(if (even? n)
(reverse (factlist(- n 1)))
(reverse (factlist n))
)
)
;-------------------------------
(define a 2n-1!-list-a)
(define b 2n-1!-list-b)