require 'pp' a = [1, 2, 3, 4, 5, 6] b = [1, 2, 3, 4, 5, 6] c = [] a.each_with_index do |ai, i| b.each_with_index do |bj, j| c[i] ||= [] c[i][j] = ai * bj end end pp a pp b pp c
Standard input is empty
[1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6] [[1, 2, 3, 4, 5, 6], [2, 4, 6, 8, 10, 12], [3, 6, 9, 12, 15, 18], [4, 8, 12, 16, 20, 24], [5, 10, 15, 20, 25, 30], [6, 12, 18, 24, 30, 36]]