Search code examples
mathluareverse-engineering

How would I implement this inverse exponential in lua?


11 -> 3
10 -> 3.1
9 -> 3.333
8 -> 3.5
7 -> 3.7142857142857
6 -> 4
5 -> 4.4
4 -> 5
3 -> 5.666
2 -> 7
1 -> 10

Basically I'm trying to reverse engineer a function for calculating Xp awarded to a player. The first number is what you feed into the function, while the second number is what it returns. After visualizing the returned numbers I figured out that they're an inverse exponential, but I've had no luck in implementing them in lua.


Solution

  • for n = 1, 11 do
       local xp = math.floor(10 * n^.5)/n
       print(n, xp)
    end
    

    Output:

    1   10
    2   7
    3   5.6666666666667
    4   5
    5   4.4
    6   4
    7   3.7142857142857
    8   3.5
    9   3.3333333333333
    10  3.1
    11  3