Created
August 28, 2018 13:14
-
-
Save gstark/14d033b19be954ca22ca56b886d706b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum_groups(arr) | |
loop do | |
chunks = arr.chunk(&:even?).map(&:last) | |
return arr.length if chunks.all? { |list| list.size == 1 } | |
arr = chunks.map(&:sum) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment