fork download
  1. let string_of_list to_s list =
  2. "[" ^ String.concat ", " (List.map to_s list) ^ "]"
  3. let string_of_ints = string_of_list string_of_int
  4. let string_of_intss = string_of_list string_of_ints
  5. let reshape n list =
  6. let rec aux yss ys m = function
  7. | [] -> yss
  8. | x :: xs when n = m -> aux ((x :: ys) :: yss) [] 1 xs
  9. | x :: xs -> aux yss (x :: ys) (m + 1) xs
  10. in aux [] [] 1 (List.rev list)
  11. let () = print_endline (string_of_intss (reshape 2 [1;2;3;4]))
Success #stdin #stdout 0s 4336KB
stdin
Standard input is empty
stdout
[[1, 2], [3, 4]]