Skip to content

Instantly share code, notes, and snippets.

@maksar
Created June 18, 2019 19:25
Show Gist options
  • Save maksar/160954ff9c07ac7ab6b8039a97bef362 to your computer and use it in GitHub Desktop.
Save maksar/160954ff9c07ac7ab6b8039a97bef362 to your computer and use it in GitHub Desktop.
def except(input)
input.map.with_index.with_object([]) { |(_e, i), r| r << (r.last || 1) * (i.zero? ? 1 : input[i - 1]) }
end
def solution(input)
except(input).zip(except(input.reverse).reverse).map { |pair| pair.inject(:*) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment