0

i would need some advice if it is possible to get the initial number from a total number. I am trying to create a level system in my application and i need from the total experience to find the current experience level.

level 1 require 10 to complete for a total of 10
level 2 require 20 to complete for a total of 30
level 3 require 30 to complete for a total of 60
and so on....

my question is how with the " total " can i get the level number.

so if i got 100 as total it should return me 4 as level
is there a mathematic way to achieve this knowing total and that each level increment by 10 ?

1 Answers1

1

Let us break this down in terms of a mathematical series to understand how the "general term" of this series behaves

You have Level 1 corresponds to 10 XP, Level 2 corresponds to 30 XP, Level 3 corresponds to 60 XP etc.

Now, the pattern we have is that for

$$\text{XP}_{N} = XP_{N-1} + 10N$$

Now, this is what we call a "recursive series" since each term depends on the previous term. How do we simplify this so that we have $XP_N$ as only a function of $N$?

We rewrite above as

$$XP_N - XP_{N-1} = 10N$$

Now, for each value of $N$, we can put it into the above and get a set of equations

$$XP_1 - XP_0 = 10$$

$$XP_2 - XP_1 = 20$$

$$XP_3-XP_2 = 30$$ $$.$$ $$.$$ $$.$$ $$XP_N - XP_{N-1} = 10N$$

Now, we add all these equations - all the left hand sides and the right hand sides, to get

$$XP_N - XP_0 = 10+20+30+...+10N$$

Now I'm assuming at level 0, we have 0 XP, hence $XP_0 = 0$

$$XP_N = 10 \cdot \frac{N(N+1)}{2} = 5N(N+1)$$