fork download
  1. def f(a)
  2. b = a.select(&:odd?).sort
  3. a.map {|n| n.odd? ? b.shift : n}
  4. end
  5. p f [6, 5, 4, 3, 2, 1]
  6. p f [6, 5, 3, 1]
  7.  
Success #stdin #stdout 0.01s 6476KB
stdin
Standard input is empty
stdout
[6, 1, 4, 3, 2, 5]
[6, 1, 3, 5]