I'm translating a small python script into C++, for a fellow internaut.

Though the script is less than 100 lines long, I haven't finished it. In fact I'm stuck a the very beginning.

This snippet is the culprit:

The reason why he used those whimsical calculations elude me. The first thing I thought, was to remove the unnecessary steps.Code:if level < 10: base_precision = 24 + (level - 1) * 4 elif level < 20: base_precision = 24 + 8 * 4 + (level - 9) * 6 elif level < 30: base_precision = 24 + 8 * 4 + 10 * 6 + (level - 19) * 8 elif level < 40: base_precision = 24 + 8 * 4 + 10 * 6 + 10 * 8 + (level - 29) * 10 elif level < 50: base_precision = 24 + 8 * 4 + 10 * 6 + 10 * 8 + 10 * 10 + (level - 39) * 12 elif level < 60: base_precision = 24 + 8 * 4 + 10 * 6 + 10 * 8 + 10 * 10 + 10 * 12\ + (level - 49) * 14 elif level < 70: base_precision = 24 + 8 * 4 + 10 * 6 + 10 * 8 + 10 * 10 + 10 * 12 + 10 * 14\ + (level - 59) * 16 elif level < 80: base_precision = 24 + 8 * 4 + 10 * 6 + 10 * 8 + 10 * 10 + 10 * 12 + 10 * 14\ + 10 * 16 + (level - 69) * 18 else: base_precision = 24 + (8 * 4) + (10 * 6) + (10 * 8) + (10 * 10) + (10 * 12)\ + (10 * 14) + (10 * 16) + (10 * 18) + 20

That was simple enough, and it worked. But I was struck with the idea that there is a pattern in those numbers.Code:if (userTraits.level < 10) basePrecision = (userTraits.level -1) * 4 + 24; else if (userTraits.level < 20) basePrecision = (userTraits.level -9) * 6 + 56; else if (userTraits.level < 30) basePrecision = (userTraits.level -19) * 8 + 116; //........ else basePrecision = 916;

After puling my hair for while I finally I came up with this formula:

It works alright for the most part, but it's a little off for certain values of level. e.g: if level = 34, basePrecision should be 246, but my formula returns 244.4Code:basePrecision = (level * 0.1 + 3.2) * level + 20

For such a small difference I thought playing around with ceil() or floor() would even it out. The problem is that it does, but it offsets other correct values.

My math skills are next to nonexistent. Perhaps you guys can see something there that I didn't, and come up with a more accurate formula.

Any help is appreciated.

Thanks.