fork download
  1. let string_of_list to_s list =
  2. "[" ^ String.concat ", " (List.map to_s list) ^ "]"
  3. let print_list to_s list =
  4. print_endline (string_of_list to_s list)
  5. let isodd n = n mod 2 <> 0
  6. let f ns =
  7. let ms = List.sort compare (List.filter isodd ns) in
  8. let rec aux acc = function
  9. | [], _ -> acc
  10. | n :: ns, m :: ms when isodd n -> aux (m :: acc) (ns, ms)
  11. | n :: ns, ms -> aux (n :: acc) (ns, ms)
  12. in
  13. List.rev (aux [] (ns, ms))
  14. let () =
  15. let p = print_list string_of_int in
  16. p (f [6; 5; 4; 3; 2; 1]);
  17. p (f [6; 5; 3; 1])
  18.  
Success #stdin #stdout 0s 4564KB
stdin
Standard input is empty
stdout
[6, 1, 4, 3, 2, 5]
[6, 1, 3, 5]