Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*LAB_11*)
- (*[#EX_1]*)
- let fibbonaci n =
- let rec acc n b a =
- if n<= 0 then a
- else acc (n-1) (a+b) b in
- acc n 1 0 ;;
- # fibbonaci 9 ;;
- - : int = 34
- (*[#EX_2]*)
- let rec ackermann =
- function x,y ->
- if x = 0 then y+1
- else if y = 0 then ackermann (x-1, 1)
- else ackermann (x-1, ackermann (x, y-1)) ;;
- (*[#EX_3]*)
- let rec geninterval s e =
- if s > e then []
- else s :: geninterval (s + 1) e
- ;;
- geninterval 3 8;;
- (*[#EX_4]*)
- let my_not = function number ->
- if number then true
- else false ;;
- my_not(5=2);;
- let my_and = function x, y ->
- if x = false then false
- else if y = false then false
- else true ;;
- let my_or = function x, y ->
- if x = true then true
- else if y = true then true
- else false ;;
- my_and(5=5, 4=4);;
- my_or(5=5, 4=4);;
- (*[#EX_5]*)
- let rec digits = function nr ->
- if (nr/10=0) then nr::[]
- else digits ( nr/10)@[nr mod 10] ;;
- digits 543;;
- (*[#EX_6]*)
- let rec maxim lista =
- if List.length lista = 1 then List.hd lista
- else max( maxim (List.tl lista)) (List.hd lista);;
- (*[#EX_7]*)
- let rec cmmdc x y =
- if (x=y) then x else
- if (x>y) then cmmdc (x-y) y
- else cmmdc x (y-x);;
- cmmdc 5 4 ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement