2010-03-06, 12:39 PM
Lucida Wrote:Mm, interesting. I never thought of the binary approach.
Edit: But it actually doesn't save time if you want to calculate each p_n anyway. Hm...
Code:function convolute(a, b)
local p = {
min = a.min + b.min,
max = a.max + b.max,
}
for n = p.min, p.max do
local sum = 0
for k = math.max(a.min, n-b.max), math.min(a.max, n-b.min) do
sum = sum + a[k]*b[n-k]
end
p[n] = sum
end
return p
end
Time complexity
I tested this on my system and it took about 6.2 seconds to compute hits(1000, 2000, 10000). Quadratic in HP means it takes ten minutes to work with 100000 HP.
Sounds like too much... Also, I'm not using the binary approach, though it's probably easier to use that to find a relatively short path instead of going into a deep-broad-search.
Keep in mind that you do not need to calculate
if
, and max is the highest damage one could do with one attack.My calculator does not take randomized def into account. I assume that the defense is constant.
Noah

