number_of_day_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] count = 0 number_of_day_in_month.each_with_index do |item, index| month = index + 1 item.times do |day_index| day = day_index + 1 day_str = day.to_s sum_day = day_str.chars.map(&:to_i).sum if (month == sum_day) count += 1 end end end p count