let isodd n = n mod 2 <> 0
let iseven n = n mod 2 = 0
let f ns =
let rec aux acc = function
| [], _, _ -> acc
| n :: ns, o :: os, es when isodd n -> aux (o :: acc) (ns, os, es)
| n :: ns, os, e :: es -> aux (e / 2 :: acc) (ns, os, es)
in
List.rev
(aux
[] (ns, os, es
)) let () =
p (f [0; 9; 8; 4; 6; 5; 1; 2; 7; 3]);
bGV0IHN0cmluZ19vZl9saXN0IHRvX3MgbGlzdCA9ICJbIiBeIFN0cmluZy5jb25jYXQgIiwgIiAoTGlzdC5tYXAgdG9fcyBsaXN0KSBeICJdIgpsZXQgcHJpbnRfbGlzdCB0b19zIGxpc3QgPSBwcmludF9lbmRsaW5lIChzdHJpbmdfb2ZfbGlzdCB0b19zIGxpc3QpCmxldCBpc29kZCBuID0gbiBtb2QgMiA8PiAwCmxldCBpc2V2ZW4gbiA9IG4gbW9kIDIgPSAwCmxldCBmIG5zID0gCiAgbGV0IG9zID0gTGlzdC5zb3J0IGNvbXBhcmUgKExpc3QuZmlsdGVyIGlzb2RkIG5zKSBpbgogIGxldCBlcyA9IExpc3QucmV2IChMaXN0LnNvcnQgY29tcGFyZSAoTGlzdC5maWx0ZXIgaXNldmVuIG5zKSkgaW4KICBsZXQgcmVjIGF1eCBhY2MgPSBmdW5jdGlvbgogICAgfCBbXSwgXywgXyAtPiBhY2MKICAgIHwgbiA6OiBucywgbyA6OiBvcywgZXMgd2hlbiBpc29kZCBuIC0+IGF1eCAobyA6OiBhY2MpIChucywgb3MsIGVzKQogICAgfCBuIDo6IG5zLCBvcywgZSA6OiBlcyAtPiBhdXggKGUgLyAyIDo6IGFjYykgKG5zLCBvcywgZXMpCiAgaW4KICBMaXN0LnJldiAoYXV4IFtdIChucywgb3MsIGVzKSkKbGV0ICgpID0gCiAgbGV0IHAgPSBwcmludF9saXN0IHN0cmluZ19vZl9pbnQgaW4KICBwIChmIFswOyA5OyA4OyA0OyA2OyA1OyAxOyAyOyA3OyAzXSk7Cg==
[4, 1, 3, 2, 1, 3, 5, 0, 7, 9]