require 'date' count = 0 d = Date.new(2015, 1, 1) while d.year < 2016 count += 1 if d.month == d.day.to_s.split('').map(&:to_i).inject(:+) d += 1 end p count