Pouknouki

Bijection caml

Mar 16th, 2016
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.52 KB | None | 0 0
  1. let rec bij = function
  2.     | (0, 0) -> 0
  3.     | (0, y) -> bij (y-1, 0)+1
  4.     | (x, y) -> if x <= y then bij (x-1, y)+1 else bij(x, y+1)+1;;
  5. print_int(bij(4,1));;
  6. (* voila tres bien *)
  7.  
  8. let rec lexico = fun (* renvoie true si l1 > l2 *)
  9.     | [] [] -> true
  10.     | [] l -> true
  11.     | l [] -> false
  12.     | (t::q) (t2::q2) -> if t > t2 then true
  13.                         else
  14.                             if t < t2 then false
  15.                                 else
  16.                                     lexico q q2;;
  17.  
  18.  
  19. let rec ack = fun
  20.     | 0 p -> p+1
  21.     | n 0 -> ack (n-1) 1
  22.     | n p -> ack (n-1) (ack n (p-1));;
  23. print_int(ack 4 4);;
Advertisement
Add Comment
Please, Sign In to add comment