def count_happy_day_in_2015 counter = 0 1.upto(12) do |month| 0.upto(month) do |upper_digit| lower_digit = month - upper_digit break if (upper_digit > 3) || (upper_digit == 3 && lower_digit > 1) if (0..9).include?(lower_digit) counter += 1 end end end counter end p count_happy_day_in_2015