require "date" $num = 0 def count(d) mon = d.mon a = d.day / 10 b = d.day % 10 if (mon == (a + b)) $num += 1 end end crnt = Date.new(2015, 1, 1) count(crnt) loop { crnt += 1 if crnt.year != 2015 break end count(crnt) } puts $num