Created
October 12, 2020 00:44
-
-
Save shubhamkumar13/c9d033de08943b4140ce9f16b2dde94d to your computer and use it in GitHub Desktop.
Transpose in ocaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let matrix_hd = fun matrix -> List.fold_left (fun acc x -> (List.hd x) :: acc) [] matrix |> List.rev | |
let matrix_tl = fun matrix -> List.fold_left (fun acc x -> (List.tl x) :: acc) [] matrix |> List.rev | |
let transpose = fun matrix -> | |
let rec loop = fun acc matrix -> | |
match matrix with | |
| hd :: tl when (List.length hd) = 0 -> acc | |
| x -> loop ((matrix_hd x) :: acc) (matrix_tl x) in | |
loop [] matrix |> List.rev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment