The rule in a particular game is that the strength of the symbol is proportional to the triangular root of the character’s experience. For example, 15-20 experience gives 5 units, 21-27 experience gives 6 units, 28-35 experience gives 7 units. Etc. Some players are known to have gained hundreds of billions of experience.
I am trying to implement this game on an 8-bit machine, which has only three arithmetic instructions: add, subtract and divide by 2. For example, to multiply a number by 4, the program will add it to itself twice, General multiplication is much slower; I wrote a program routine to do this using a square table.
I looked at calculating the triangular root T(p)through bisection search for consecutive triangular numbers, limiting the number of experiences above and below. My plan was to use the repeat identifier for T(2*p)until it exceeded the experience, and then use it as an upper bound to search in half. But it’s hard for me to find the identifier for T((x+y)/2)half-division, which does not use either x*y, or (x+y)^2.
Is there an efficient algorithm for calculating the triangular root of a number with just adding, subtracting and halving it? Or should I end up doing O (log n) multiplication to compute each midpoint in a normal search? Or would it be better to consider the use of long division to use the Newton method?
Definition T(x):
T(x) = (n * (n + 1))/2
The identities I received are:
T(2*x) = 4*T(x) - x
# e.g. T(5) = 15, T(10) = 4*15 - 5 = 55
T(x/2) = (T(x) + x/2)/4
# e.g. T(10) = 55, T(5) = (55 + 5)/4 = 15
T(x + y) = T(x) + T(y) + x*y
# e.g. T(3) = 6, T(7) = 28, T(10) = 6 + 28 + 21 = 55
T((x + y)/2) = (T(x) + T(y) + x*y + (x + y)/2)/4
# e.g. T(3) = 6, T(7) = 28, T(5) = (6 + 28 + 21 + 10/2)/4 = 15
source
share