def count_happy_day_in_2015 last_day_of_month = [31,28,31,30,31,30,31,31,30,31,30,31] counter = 0 1.upto(12) do |month| 0.upto(month) do |upper_digit| lower_digit = month - upper_digit break if upper_digit * 10 + lower_digit > last_day_of_month[month-1] if (0..9).include?(lower_digit) counter += 1 end end end counter end p count_happy_day_in_2015