Skip to content

Instantly share code, notes, and snippets.

@kharioki
Created September 29, 2016 20:16
Show Gist options
  • Select an option

  • Save kharioki/bd21cb20a309777f7857a8c95e021bad to your computer and use it in GitHub Desktop.

Select an option

Save kharioki/bd21cb20a309777f7857a8c95e021bad to your computer and use it in GitHub Desktop.
def product_except?(d)
e = []
startvalue = 0
endvalue = d.length
product = d.inject(1){|first,n| first * n}
result = []
while startvalue < endvalue
result.push(product/ d[startvalue])
startvalue = startvalue + 1
end
puts "#{result}"
end
product_except?([1,2,3,4,5,6,7,8,9])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment