Last active
September 13, 2016 02:51
-
-
Save jeanlescure/5cc9795546737b908147a7f4f62ce3f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 get_products_of_all_ints_except_at_index arr | |
arr.map do |i| | |
filtered = arr.select do |j| | |
i != j | |
end | |
filtered.reject(&:zero?).inject(:*) | |
end | |
end | |
# eval is evil | |
int_array = gets.match(/\[(.+)\]/)[1].split(',').map do |l| l.to_i end | |
result = get_products_of_all_ints_except_at_index int_array | |
puts '[' + result.join(',') + ']' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment