cal = (1..31).map { |i| i } sum_day = cal.map do |d| if d < 10 d elsif d >= 10 d / 10 + d % 10 end end count = 0 (1..12).each do |x| y = sum_day.select { |n| n == x } count += y.length end p count