Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- ;zadanie 5
- (define (odd? n)
- (cond [(zero? n) #f]
- [else (even? (- n 1))]))
- ;zadanie 6
- (define (fibRek n)
- (cond
- ((= n 0) 0)
- ((= n 1) 1)
- (else (+ (fibRek (- n 1)) (fibRek(- n 2))))))
- (define (fibIt n)
- (fib-iter 1 0 n))
- (define (fib-iter a b count)
- (if (= count 0)
- b
- (fib-iter (+ a b) a (- count 1))))
- ;(fibRek 6)
- ;(fibIt 6)
- ;zadanie 7
- (define (exp b e)
- (cond
- ((or (= b 1) (= e 0)) 1)
- ((= (modulo e 2) 0) (expt (exp b (/ e 2)) 2))
- (else (* b (exp b (- e 1))))))
- ;(exp 2 6)
- ;zadanie 8
- (define (max-two a b c)
- (if (>= a b)
- ;; then
- (if (>= b c)
- (cons a b)
- (cons a c))
- ;; else
- (if (>= a c)
- (cons b a)
- (cons b c))))
- (define (sum-of-squares x y)
- (+ (* x x) (* y y)))
- (define (sum-of-squares-of-maxima a b c)
- (sum-of-squares (car (max-two a b c)) (cdr (max-two a b c))))
- ;zadanie 9
- (define (call f x)
- (f x))
- ;(call odd? 7)
- ;zadanie 10 - kolejność sprawdzania warunków
- (define (new-if warunek alternatywa1 alternatywa2)
- (cond (warunek alternatywa1)
- (else alternatywa2)))
- ;(new-if (> 1 2) 1 2)
- ;zadanie 12 - zasięg lokalny / globalny zmiennych
- (define m 1)
- (define (p m)
- (pp 5))
- (define (pp x)
- (+ x m))
- (define n 1)
- (define (q n)
- (define (qq x)
- (+ x n))
- (qq 5))
- ;(p 11)
- ;(q 11)
- ;zadanie 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement