League of Legends optimal items In the popular game League of Legends, your effective amount of hit points ($E$) against physical damage is a function of your actual hit points ($H$) and the amount of armor ($A$) you have.
$$E = H\left(\frac{A+100}{100}\right)$$
You can increase your hit points and armor by buying items.


*

*$20$ gold per $1$ armor

*$\frac 83$ gold per $1$ hit point


Given a state $(h,a,x)$ where $h$ is your current amount of hit points, $a$ is your current amount of armor, and $x$ is the amount of gold you have, how much of each (armor and hit points) should you buy to maximize your effective hit points $e$?
I was told that this problem requires Lagrange multipliers, but I haven't learned that yet so I don't know what to do.
 A: Let $h$ be your current health, $a$ be your current armor, $q$ be your current amount of gold, $x$ be the amount of health you buy, and $y$ be the amount of armor you buy.
We are trying to maximize the function:
$$f(x,y;h,a) = (h+x)\left(\frac{a+y+100}{100}\right)$$
$$\text{w.r.t.:}\ \   g(x,y;q)=\frac83x+20y - q=0$$
To use the method of Lagrange multipliers, we want:
$$\frac{\partial f}{\partial x} = -\lambda\frac{\partial g}{\partial x}$$
$$\frac{\partial f}{\partial y} = -\lambda\frac{\partial g}{\partial y}$$
Plugging in the equations gives:
$$\frac{a+y+100}{100} = -\frac83\lambda$$
$$\frac{h+x}{100} = -20\lambda$$
If we include the equation:
$$\frac83x+20y - q=0$$
We now have three equations for our variables $\{x,y,\lambda\}$. We can solve these to get:
$$x = -\frac{1}{2}h + \frac{15}{4}a + \frac{3}{16}q + 375$$
$$y = \frac{1}{15}h - \frac{1}{2}a + \frac{1}{40}q - 50$$
This will tell you how much health ($x$) and armor ($y$) to buy. Note that these values can become negative: in the case either one is negative, the implication is to buy none of that stat and spend all of your money on the other.
The limitation here is that I assume you can spend any real number of gold to buy any real number of a stat: for example, I can spend $30$ gold to purchase $1.5$ points of armor. This isn't true in the actual game (there are no fractional values for hit points, armor, or gold), so the results produced by this procedure should be taken with a grain of salt.
To fix this, I would recommend not using Lagrange multipliers and instead iterating through the combinations of: spending $8x$ gold for $3x$ hit points and spending $20y$ gold for $y$ armor, where $x,y \in \Bbb{N}$.
In this case, you are trying to maximize:
$$(h+3x)\left(\frac{a+y+100}{100}\right)$$
$$\text{w.r.t.:}\ \   8x + 20y \le q \ \text{and} \ x,y \in \Bbb{N}$$
Since there are finitely many $\{x,y\}$ that satisfy this condition, you can iterate through them all and choose the maximum value for expected health. This is something MATLAB or Excel could handle pretty well.
UPDATE
In fact, in League of Legends, there is a minimum denomination of health and armor you can buy.
The lowest amount of health you can buy is a Ruby Crystal, which gives you $150$ hit points for $400$ gold. The lowest amount of armor you can buy is a Cloth Armor, which gives you $15$ armor for $300$ gold. I'm assuming this is where you derived your values for unit price ($\frac{400}{150} = \frac{8}{3}$, $\frac{300}{15} = 20$).
Now the problem becomes a bit easier to exhaust all the options.
If we say $x$ is the number of Ruby Crystals we buy and $y$ is the number of Cloth Armors we buy, we are trying to maximize:
$$(h+150x)\left(\frac{a+15y+100}{100}\right)$$
$$\text{w.r.t.:}\ \   400x + 300y \le q \ \text{and} \ x,y \in \Bbb{N}$$
A: For every amount of gold there is an area of possible combinations of armor and hit points you can purchase. Clearly it is best to spend all your gold so the optimal solutions will be somewhere on the edge of that area. That is the general idea of Lagrange multipliers.
Let $f(x,y) = E(H,A)$ and $g(x,y) = \text{gold} - 20A - \frac{8}{3} H$ and try fallowing the example.
