require 'date' d = Date.new(2015) puts((d...(d + 365)).count { |e| e.month == e.day.digits.sum })