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