Arithmetic Progression Formula
I'm having trouble trying to figure out arithmetic progressions. I'm looking for a formula with an output that increases by 100 more than it's last increase... like this:
100, 300, 600, 1000, 1500
So the increase pattern looks like this:
(100+)200, (300+)300, (600+)400, (1000+)500, etc
2 hours and 2, front and back, scratch papers have yeilded no such formula. I'm hoping this makes since because my brain is litera开发者_StackOverflow社区lly fried right now.
This is essentially a level-up formula for an rpg. When you are level 1 you need 100 exp to level up. Level 1: 100 (increased by 100)
Level 2: 300 (increased by 200)
Level 3: 600 (increased by 300)
Level 4: 1000 (increased by 400)
and so on...
I don't feel like hardcoding the levels, so will someone please help me.
write down all your expressions :
level i = leveil i-1 + i*100
level i-1 = level i-2 + i-1 * 100
...
level 1 = level 0 + 100
then summing up these formulas one level k Left hand side eliminate the next one level k right hand side, and you get :
Level i = level 0 + sum(k , k=1 to i)*100
then level i = i*(i+1)/2 *100
That's just a simple triangular number equation.
k * n * (n + 1) / 2
where k=100
and n=1,2,3,...
. You can obtain your list like this:
k = 100
n_max = 10
for n in range(1, n_max):
print k * n * (n + 1) / 2
where n_max
is the number of elements you need.
精彩评论