Skip to content

Instantly share code, notes, and snippets.

View lAnubisl's full-sized avatar
🇺🇦
Glory to Ukraine

Alexander Panfilenok lAnubisl

🇺🇦
Glory to Ukraine
View GitHub Profile
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