exception Empty_list let fold fn = function | [] -> raise Empty_list | head :: tail -> List.fold_left fn head tail let list_min ls = fold Stdlib.min ls let list_max ls = fold Stdlib.max ls let rec repeat n a = if n <= 0 then [] else a :: repeat (n - 1) a let empty ls = ls = [] let rec zip l1 l2 = match (l1, l2) with | [], _ -> [] | _, [] -> [] | h1 :: t1, h2 :: t2 -> (h1, h2) :: zip t1 t2 let rec transpose = function | [] :: _ -> [] | ls -> List.(map hd ls) :: transpose List.(map tl ls) let flip f a b = f b a let rot_right ls = List.(rev ls |> transpose) let rot_left ls = List.(transpose ls |> rev) let saturating_sub b a = if a < b then 0 else a - b let to_string c = String.make 1 c let space = to_string ' ' let axis = "┬" let axis_spc = "─"