How to solve equation with multiple variables with each of them having different "weight"? I need to solve equation where the goal is to buy specific number of snacks for the lowest price.
There are 7 types of snack packages, each of them contains different number of snacks and has different price, here is the list:

*

*A: 0.0051 $ / 4 snacks


*B: 0.0102 $ / 4 snacks


*C: 0.0204 $ / 8 snacks


*D: 0.0408 $ / 17 snacks


*E: 0.0816 $ / 35 snacks


*F: 0.1632 $ / 58 snacks


*G: 0.3264 $ / 58 snacks
Now I need to know, how to get the best "combo of packages" for lowest price when buying 10 snacks, 20 snacks..... up to 100 snacks. (When 10 is needed, buying some extra is not problem - such as buying 12 instead of 10.)
I tried bruteforcing (such as starting from maximum number of cheapest package and then combining with other packages), but I think there mast be some smarter way to solve this. :)

Maybe a too long answer for what the outcome is.
This is generally referred to as the Knapsack problem.
Mathematically formulated as:
$$minimize \sum_{i=1}^n G_i(s_i)$$
s.t.
$$ \sum_{i=1}^n s_i = V,$$
$$ s_i \ge 0$$
where $G_i(s_i)$ is the price per snack times the number of snacks and $V$ is your total number of snacks you want to buy.
You can solve this via multiple ways (e.g. dynamic programming, Lagrangian relaxation, ...)
You can also do a marginal analysis algorithm, where you first calculate $\Delta G_i(s_i)$ for all $i$ and then as long as $\sum_{i=1}^n s_i < V$ you iteratively increases the amount for the snack where $ \frac{\Delta G_i}{s_i} $ is the smallest.
So in your problem: where the price per snack is the smallest.
Thus in your problem you just need to buy A...
