def f(a)
b = a.select(&:odd?).sort
a.map {|n| n.odd? ? b.shift : n}
end
p f [6, 5, 4, 3, 2, 1]
p f [6, 5, 3, 1]
ZGVmIGYoYSkKICBiID0gYS5zZWxlY3QoJjpvZGQ/KS5zb3J0CiAgYS5tYXAge3xufCBuLm9kZD8gPyBiLnNoaWZ0IDogbn0KZW5kCnAgZiBbNiwgNSwgNCwgMywgMiwgMV0KcCBmIFs2LCA1LCAzLCAxXQo=
[6, 1, 4, 3, 2, 5]
[6, 1, 3, 5]