Home > other >  How do I increase the gap between each of these numbers?
How do I increase the gap between each of these numbers?

Time:09-23

So I'm trying to make an algorithm for XP requirements for each level in a project I'm working on and I have a basic algorithm setup however I can't figure out how to increase the gap between each requirement.

My goal is for it to start off around 750 between each level and after around 15 levels it starts increasing to around 1000 per level and just kind of increase like that. I was thinking logarithmic functions but I couldn't figure out how to get one to work as I want it.

Here's my algorithm right now plus the requirements it returns. It's not a log function right now because this is as close to what I wanted as possible but I feel like that might be the direction I should be heading.

function lvlAlg(level) {
    let Alg = (level)   (600 * level)   100;
    return Alg;
}

// Level 1: 701
// Level 2: 1302
// Level 3: 1903
// Level 4: 2504
// Level 5: 3105
// Level 6: 3706
// Level 7: 4307
// Level 8: 4908
// Level 9: 5509
// Level 10: 6110

CodePudding user response:

If you want the gap to increase smoothly from 750 to 1000 when you go from level 1 to 15, calculate (1000/750) ** (1/14) to get the exponent for each level. The value of this is about 1.0208.

function lvlAlg(level) {
    let Alg = (level)   level*750*(1.0208**level)   100;
    return Alg;
}

for (let i = 1; i < 20; i  ) {
  console.log(i, Math.round(lvlAlg(i)));
}

  • Related