Skip to content

Instantly share code, notes, and snippets.

@jeanlescure
Last active September 13, 2016 02:51
Show Gist options
  • Save jeanlescure/5cc9795546737b908147a7f4f62ce3f3 to your computer and use it in GitHub Desktop.
Save jeanlescure/5cc9795546737b908147a7f4f62ce3f3 to your computer and use it in GitHub Desktop.
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