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 sum_day1 = sum_day.dup sum_day2 = sum_day.dup sum_day3 = sum_day.dup sum_day2.delete_at(30) sum_day3.slice!(28, 3) count = 0 (1..12).each do |x| case x when 1, 3, 5, 7, 8, 10, 11, 12 y = sum_day1.select { |n| n == x } count += y.length when 4, 6, 9 y = sum_day2.select { |n| n == x } count += y.length when 2 y = sum_day3.select { |n| n == x } count += y.length end end puts count