From: ex [mailto:exeQtor / gmail.com] # ################## # There is an array A[N] of N integers. You have to # compose an array # Output[N] such that Output[i] will be equal to the # product of all the elements of A[] except A[i]. # # Example: # INPUT:[4, 3, 2, 1, 2] # OUTPUT:[12, 16, 24, 48, 24] # # Note: Solve it without the division operator and in O(n). # ============================================================= it's friday here, so i guess i'll just join the fun :) how about, prod= lambda{|a| a.inject(1){|p,x| p*x}} => #<Proc:0xb7d708e0@(irb):1> a=[4,3,2,1,2] => [4, 3, 2, 1, 2] pa=[] => [] s=a.size => 5 s2=s-1 => 4 # here is the meat: # i just concat orig array so i don't need to rotate # then get subarrays in groups of s2 (a.size-1) a2=a+a => [4, 3, 2, 1, 2, 4, 3, 2, 1, 2] 1.upto(s) do |i| pa << prod.call(a2[i,s2]) end => 1 p pa [12, 16, 24, 48, 24] => nil can i pass google? =) kind regards -botp