Skip to content

Instantly share code, notes, and snippets.

@vlmonk
Created May 17, 2012 13:55
Show Gist options
  • Save vlmonk/2719087 to your computer and use it in GitHub Desktop.
Save vlmonk/2719087 to your computer and use it in GitHub Desktop.
class Array
def complect n
sum = self.reduce { |sum, x| sum + x }
first = sum - n + 1
[first] + [1] * (n - 1)
end
end
puts [2, 3, 4, 5].complect(2).join(', ')
puts [2, 5, 3, 6].complect(2).join(', ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment