Ruby - Summing groups of odd and even integers in an array until no groups remain
The whole thing about sums is misdirection; you don't need to sum anything, since all you need to output is the final length of the array. So what you want to know is how many consecutive terms there are of a given parity, not what their sum is.

The trick is that only an odd number of odd terms will produce an odd sum; anything else will produce an even sum. So you can skip calculating the actual sum, because by knowing the parity and number of terms, you'll know if that sum's going to be odd or even.

Secondly, you can make it recursive instead of loop-based.

Here's my take:

def count_chunks_recursively(array)
  # get our consecutive chunks
  chunks = array.chunk(&amp;:odd?).to_a

  # if there are as many chunks as there are elements, we're done
  return array.size if chunks.size == array.size

  # otherwise, map the chunks to 0 or 1, depending on whether they
  # sum up to something even or something odd
  mapped = chunks.map { |odd, terms| odd &amp;&amp; terms.size.odd? ? 1 : 0 }

  # ... and repeat the process recursively
  count_chunks_recursively(mapped)
end


As for your current code:


You very, very rarely have to use plain loops in Ruby; there's almost always something in Enumerable or Array that you can use instead.
x[-1].size would be more conventionally written as x.last.size
You use the a method reference when producing the sum – inject(&amp;:+) – but you don't use the same technique for the other parts of the same line. I.e. this

arr.chunk{|x| x.even?}.map{|x, y| y}.map{|x| x.inject(&amp;:+)}


could just be this:

arr.chunk(&amp;:even?).map(&amp;:last).map { |x| x.inject(&amp;:+) }


or in Ruby 2.4+ which has a built-in sum method:

arr.chunk(&amp;:even?).map(&amp;:last).map(&amp;:sum)


Sidenote: inject (specifically) actually doesn't need the method reference, but can also take a plain symbol: inject(:+). But for consistency's sake, I'd stick to using the &amp;.