Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* Zadanie 2a*)
- let rec fib n =
- match n<2 with
- | true -> if n < 0 then failwith "ujemny argument" else n
- | false -> fib(n-2) + fib(n-1)
- (* Zadanie 2b*)
- let fib_tl n =
- let rec fib_tl_h n ak w =
- match n = 0 with
- | true -> ak
- | false -> fib_tl_h (n-1) w (ak+w)
- in
- match n>0 with
- | true -> fib_tl_h n 0 1
- | false -> failwith "ujemny argument"
- (* Zadanie 3*)
- let root3 a =
- let rec root3_rt x =
- match abs_float(x ** 3. -. a) <= 1e-15 *. abs_float(a) with
- | true -> x
- | false -> root3_rt (x +. ( a /. (x ** 2.) -. x) /. 3.)
- in match a <= 1. with
- | true -> root3_rt(a)
- | false -> root3_rt(a/.3.)
- (* Zadanie 4a*)
- let [_;_;x;_;_] = [-2;-1;0;1;2]
- (* Zadanie 4b*)
- let [(_,_);(y,_)] = [(1,2);(0,1)]
- (* Zadanie 5*)
- let rec initSegment (lista1, lista2) =
- match (lista1, lista2) with
- | ([],_) -> true
- | (h1::t1,h2::t2) -> h1=h2 && initSegment(t1,t2)
- | _ -> false
- (* Zadanie 6*)
- let rec replaceNth(lista, nth, elem) =
- match lista with
- | [] -> []
- | h::t -> (if nth=0 then elem else h) :: replaceNth (t,(nth-1), elem)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement