brewersfan1976

array_conversion2.rb

Oct 15th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.90 KB | None | 0 0
  1. def arrayConversion(inputArray)
  2.     x = 1
  3.     output = Array.new
  4.     tmp = Array.new
  5.     output = inputArray
  6.    
  7.     while (output.length > 1)
  8.           if x % 2 != 0 then
  9.              y = 0
  10.              z = 0
  11.              
  12.              while (y < output.length - 1)
  13.                    tmp[z] = output[y] + output[y + 1]
  14.                    z = z + 1
  15.                    y = y + 2
  16.              end
  17.              
  18.              output = tmp
  19.           end
  20.              
  21.           if x % 2 == 0 then
  22.              y = 0
  23.              z = 0
  24.              
  25.              while (y < output.length - 1)
  26.                    tmp[z] = output[y] * output[y + 1]
  27.                    z = z + 1
  28.                    y = y + 2
  29.              end
  30.              
  31.              output = tmp
  32.           end
  33.          
  34.           x = x + 1
  35.           tmp = Array.new
  36.     end
  37.              
  38.     return output[0]
  39. end
Advertisement
Add Comment
Please, Sign In to add comment