let reverse arr = let lg = Array.length arr in
  for k = lg-1 downto 0 do
    arr.(k) <- arr.(lg-1-k)
  done