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| month.downto(0) do |upper_digit| next if upper_digit > 3 lower_digit = month - upper_digit break if lower_digit > 9 next if upper_digit * 10 + lower_digit > last_day_of_month[month-1] counter += 1 end end counter end p count_happy_day_in_2015