Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Pierwsze zajecia Scheme
- (define (silnia n)
- (if (< n 2)
- 1
- (* n (silnia (- n 1))))
- )
- (define (silniaK n k)
- (if (= n 1)
- (k 1)
- (silniaK (- n 1) (lambda (x) (k (* n x))))
- )
- )
- (define (id x) x)
- (define (silniaI n)
- (do ((wynik n (* wynik n))) ((< n 2) wynik) (set! n (- n 1))))
- (define (fib n)
- (if (<= n 2)
- 1
- (+ (fib (- n 1)) (fib (- n 2))))
- )
- (define (rowne x y)
- (if (= x y)
- (display "sa rowne")
- (display "nie sa rowne"))
- )
- (do ((i 0 (+ i 1)) (suma 0 suma)) ((> i 6) suma) (set! suma (+ suma i)))
- ;potega w O(n) (zlozonosc liniowa)
- ;potega w O(n) w stylu kontynuacyjnym
- ;NWD:
- (define (GCD a b)
- (cond [(= b 0) a]
- [else (GCD b (modulo a b))]))
- ;Lata przestepne
- (define (rokP rok)
- (or (and (zero? (remainder rok 4))
- (not (zero? (remainder rok 100))))
- (zero? (remainder rok 400))))
- (define dniWMies (lambda (n)
- (case n
- ((2) 28)
- ((4 6 9 11) 30)
- (else 31))))
- ;Drugie zajecia Scheme
- (define (potegaZle a n)
- (if (= n 0) 1 (* a (potegaZle a (- n 1)))))
- (define (id x) x)
- (define (potegaKontynuacyjnie a n k)
- (if (= n 0) (k 1) (potegaKontynuacyjnie a (- n 1) (lambda (x) (k (* a x))))))
- ;Listy: '(1 4 2 a (e f))
- ;Lista '(a b c) to drzewo:
- ; .
- ;/ \
- ;a .
- ; / \
- ; b .
- ; / \
- ; c '()
- ;Długość listy:
- ;car - pierwszy element
- ;cdr - ogon listy
- (define (dlugosc l)
- (if (null? l) 0
- (+ 1 (dlugosc (cdr l)))))
- (define (dlugoscK l k)
- (if (null? l) (k 0)
- (dlugoscK (cdr l) (lambda (x) (k (+ 1 x))))))
- ;Połączenie dwóch list:
- ;cons - konstruktor par (a . b) <-para
- (define (polacz a b)
- (if (null? b) a
- (if (null? a) b
- (cons (car a) (polacz (cdr a) b)))))
- ;Odwracanie listy
- (define (odwroc a)
- (if (null? a) '()
- (polacz (odwroc (cdr a)) (list (car a)))))
- ;Odwracanie v2
- ;Odwracanie 'kontynuacyjne'
- ;(define (odwrocK a '())
- ; (if (null? a) '()
- ; (while (= a '())...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement