require 'date' ans=(1..12).map do |m| (1..Date.new(2015,m,-1).day).map do |d| dd=d/10 1 if m==d-9*dd end.compact.inject(:+) end.compact.inject(:+) p ans