n = [1,3,5,7,8,10,12] m = [4,6,9,11] c = 0 n.each do |i| 4.times do |j| 10.times do |k| c += 1 if i == j + k p i , j , k end end end m.each do |i| 4.times do |j| 10.times do |k| c += 1 if i == j + k p i , j , k end end end 2.times do |j| 28.times do |k| c += 1 if 2 == j + k p j , k end end p c