daylast = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] hd = 0 (1..12).each do |i| limit = daylast[i - 1] (1..limit).each do |x| m = x / 10 l = x % 10 if i == m + l hd += 1 end end end puts hd