-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpract1.rkt
59 lines (43 loc) · 984 Bytes
/
pract1.rkt
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
52
53
54
55
56
57
58
#lang racket
(define
(name gosho pesho)
(* gosho pesho)
)
(if (eq?(name 4 3) 12) 4 5)
(define (succ x) (+ x 1))
(define (pred x) (- x 1))
;(define (my-plus x y)
; (if (> y 0) (my-plus (succ x) (pred y)) x))
; doesnt work for negatives
(define (my-plus1 x y)
(if (= x 0) y
(succ (my-plus1 (pred x) y))))
(define (my-mult x y)
(if (= x 1) y
(my-plus1 y (my-mult (pred x) y))
)
)
(define (my-pow x y)
(if (= y 1) x
(my-mult x (my-pow x (pred y)))
)
)
(define (fast-pow x y)
(if (= y 1) x
(* (fast-pow (* x x) (quotient y 2))
(if (= (remainder y 2) 1) x 1) )
)
)
(define (factoriel x)
(if (= x 1) x
(my-mult (factoriel (pred x)) x)
)
)
(define (fibonacci x)
(if (= x 1) 1
(if (= x 0) 1
(+ (fibonacci(pred x)) (fibonacci(pred (pred x))))
)
)
)
(fibonacci 20)