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