0

I'm making a level calculation system, based on geometric progression, with initial term $a_1=100$ and ratio $r=2$.

So, we have an equation for min. $x$ and max. $a$ XP values per level $n$:

$a_n = a_1*r^{n-1} \\ x_n = a_{n-1} = a_1*r^{n-2}$

I need to get a level (aka. $a$ term) basing on current player's XP (aka. $p$ point), like in next four examples:

$p = 64 = a_1 \\ p = 128 = a_2 \\ p = 256 = a_3 \\ p = 512 = a_4$

What formula will suit me in this case?

1 Answers1

0

$a_n=100 \cdot 2^{n-1}$ seems to be what you want

Added: if you are given a value $x$ and want to find the closest $a_n$ by ratio, you can just compute $\log_2 \frac x{100}$ and round to the nearest whole number, then add $1$. For example if you are given $142$ you do $\log_2 \frac {142}{100}\approx 0.5059$, which rounds to $1$. Adding $1$ gets $2$, so the closest value is $a_2$. The addition of $1$ comes from the fact that we counted from $1$.

Ross Millikan
  • 374,822
  • is that a joke or what wtf man. this formula finding nth term, not nearest term for point. it's so sad that i can't dislike u. please, read my post against. – nesclass Jul 13 '19 at 02:07
  • I didn't find it clear what you were trying to ask. If you are given a number and are trying to find the closest $a_n$, do you mean closest in arithmetic terms or in geometric terms? $142$ is closer to $100$ than $200$ in arithmetic terms because the difference is $42$ compared to $58$, but is further in geometric terms because $\frac {142}{100} \gt \frac {200}{142}$ – Ross Millikan Jul 13 '19 at 02:10
  • ok, i mean closest geometric term. – nesclass Jul 13 '19 at 02:12
  • yay, that's what i need. thx – nesclass Jul 13 '19 at 02:35