dodani fajli z vajami stari
parent
4da40fc948
commit
b4dad87166
|
@ -0,0 +1,12 @@
|
|||
(define (A x y)
|
||||
(cond ((= y 0) 0)
|
||||
((= x 0) (* 2 y))
|
||||
((= y 1) 2)
|
||||
(else (A (- x 1) (A x (- y 1))))
|
||||
)
|
||||
)
|
||||
|
||||
(define (f n) (A 0 n))
|
||||
(define (g n) (A 1 n))
|
||||
(define (h n) (A 2 n))
|
||||
(define (k n) (A 3 n))
|
|
@ -0,0 +1,80 @@
|
|||
;; naloga 1.11
|
||||
|
||||
(define (rec-f n)
|
||||
(if (< n 3) n
|
||||
(+ (rec-f (- n 1)) (* 2 (rec-f (- n 2))) (* 3 (rec-f (- n 3))))
|
||||
)
|
||||
)
|
||||
|
||||
;; iterativno - nosimo rezultat naprej
|
||||
;; narobe
|
||||
(define (iter-f a b c d cnt)
|
||||
(if (= cnt 0)
|
||||
a
|
||||
(iter-f (+ b (* 2 c) (* 3 d)) a b c (- cnt 1))
|
||||
)
|
||||
)
|
||||
|
||||
(define (ief n) (iter-f 4 2 1 0 n))
|
||||
;; poskus 2
|
||||
(define (itr-f a b c cnt)
|
||||
(if (= cnt 0) a
|
||||
(itr-f (+ a (* 2 b) (* 3 c)) a b (- cnt 1))
|
||||
)
|
||||
)
|
||||
(define (ief2 n) (itr-f 2 1 0 n))
|
||||
|
||||
;; naloga 1.12
|
||||
;; pascalov trikotnik - rekurzivna funkcija
|
||||
|
||||
;; https://spritely.institute/static/papers/scheme-primer.html
|
||||
|
||||
(define (build-tree depth)
|
||||
(if (= depth 0)
|
||||
'(0)
|
||||
(list depth
|
||||
(build-tree (- depth 1))
|
||||
(build-tree (- depth 1))
|
||||
)
|
||||
)
|
||||
)
|
||||
;; mam seznam in ubistvu samo sestejem dve sosednji stevilki v seznamu
|
||||
;; (car sez)
|
||||
|
||||
(define (nov-seznam sez)
|
||||
(define (prvi sez) (car sez))
|
||||
(define (drugi sez) (if (null? (cdr sez)) 0 (car (cdr sez))) )
|
||||
(if (= 0 (drugi sez))
|
||||
sez
|
||||
(cons (+ (prvi sez) (drugi sez)) (nov-seznam (cdr sez)))
|
||||
)
|
||||
)
|
||||
|
||||
(define (pascal globina seznam)
|
||||
(display seznam)
|
||||
(if (= globina 0)
|
||||
seznam
|
||||
(pascal (- globina 1) (cons 1 (nov-seznam seznam)))
|
||||
)
|
||||
)
|
||||
|
||||
(define (p n) (pascal n '(1 1)))
|
||||
|
||||
;; stack overflow
|
||||
(define (pascal-so x y)
|
||||
(define (sub1 z) (- z 1))
|
||||
(if (or (zero? y) (= x y))
|
||||
1
|
||||
(+ (pascal-so (sub1 x) y)
|
||||
(pascal-so (sub1 x) (sub1 y)))))
|
||||
|
||||
;; 1.15 aproksimacije sinusa
|
||||
(define (cube x) (* x x x))
|
||||
(define (prib x) (- (* 3 x) (* 4 (cube x))))
|
||||
;; cnt bi lahko defaultno nastavil na nic, ce bi znal
|
||||
(define (sine angle cnt)
|
||||
(if (not (> (abs angle) 0.1))
|
||||
angle
|
||||
(prib (sine (/ angle 3.0) (+ cnt 1)))
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue