ruby -we '@tri = (0 .. 10).map {|c| c * (c + 1) / 2; }; @a = (0 .. 10).map { (0 .. 400).map { Array.new(101); }; }; def res c = 10, t = 667, m = 101; (t2 = c * m - t) < t and t = t2; if t <= 0; if t == 0 && c == 0; 1 else 0 end; else @a[c][t][m] ||= (g = @tri[c - 1]; ((t + g)/c .. [m - 1, t - g].min)).inject(0) {|r, x| r + res(c - 1, t - x, x); } end; end; puts r = res; r == 14479062752 or fail;'