require 'date' list = (Date.new(2015, 1, 1)..Date.new(2015, 12, 31)).select do |v| v.day.to_s.split('').sum(&:to_i) == v.month end p list.count