Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.49 KB | None | 0 0
  1. let bool_bin = function
  2.     |true -> 1
  3.     |false -> 0
  4. let rec binList xs ys = match xs with
  5.     |[] -> ys
  6.     |x::xs -> binList xs ((bool_bin x)::ys)
  7. let rec pow a = function
  8.   | 0 -> 1
  9.   | 1 -> a
  10.   | n ->
  11.     let b = pow a (n / 2) in
  12.     b * b * (if n mod 2 = 0 then 1 else a)
  13. let rec bin_dec xs ys position= match xs with
  14.     |[] -> ys
  15.     |x::xs when position = 0 -> bin_dec xs (x+ys) (position+1)
  16. |x::xs when position <> 0 -> bin_dec xs (x* (pow 2 position) 0)+ys) (position+1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement