The two basic facts you need to know are the following:
- If you multiply two numbers by the same "scaling factor", their ratio stays
the same. For example, the ratios
"$10:3$", "$20:6$", "$30:9$" and "$100:30$" are all the same.
(In fact, their ratio will stay the same "only if" you multiply them by the
same number. If you multiply them by different numbers, the ratio will
change).
- If you have a bunch of numbers and you know their sum, if you make a new bunch
of numbers by multiplying them all by some "scaling factor", the sum of the
new numbers is the sum of the old numbers times the scaling factor. For
example, the sum of $4$, $6$, $7$ is $17$, and the sum of $12$, $18$, $21$ is
$51$, which is $3 \times 17$.
These really do just sort of come from a certain familiarity with maths, and it
can be hard for mathematicians on the internet to empathise with people that
aren't mathematicians, so I appreciate that you've had a hard time Googling!
So suppose you have your set of numbers:
$20$, $30$, $45$, $50$, $20$, totalling $165$.
For the purposes of this discussion, I will "simplify" your quantities - I never
said you had to multiply by a whole number, so I'm going to multiply by
$\frac 15$!${}^{\text{No jokes about $\Gamma$ please}}$
We now have the numbers
$4$, $6$, $9$, $10$, $4$, totalling $33$. (These are "simple" because I can't
divide them by anything else while keeping them all intact)
We want to make their sum be $300$. Unfortunately, this isn't possible! That's
because $300$ is not a multiple of $33$. We have two options now - we can keep
their ratios completely correct, but not quite make the right sum. We could make
the sum $297$ or $330$, which are the two closest multiples of $33$ to $300$.
(We'd do this by multiplying by $9$ or $10$, respectively). Here it's really
your call if you'd rather over-shoot or under-shoot.
Alternatively, we could try and get the sum exactly by just multiplying by
$300/33$, leaving us with some non-whole numbers. At this point you'd have to
round all your numbers somehow. You could round them all up, or down, or to the
nearest integer.
If you want the total to be exactly $300$ (or whatever number), there are a
number of approaches and really it becomes more of a programming job. See for
example the techniques described at
https://stackoverflow.com/questions/13483430/how-to-make-rounded-percentages-add-up-to-100.
If it's easier for you to see it in code, here's a simple Python program
exhibitively implementing two of the approaches I mentioned:
from functools import reduce
from math import gcd
numbers = [20, 30, 45, 50, 20]
def make_sum1(numbers, n):
"""
Return a list of numbers in the same ratios as `numbers`, but with sum
approximately n.
"""
num_gcd = reduce(gcd, numbers)
simplified_numbers = [number // num_gcd for number in numbers]
simplified_sum = sum(simplified_numbers)
return [number * (n // simplified_sum) for number in simplified_numbers]
def make_sum2(numbers, n):
"""
Alternative approach by rounding down
"""
num_sum = sum(numbers)
return [number * n // num_sum for number in numbers]
print(make_sum1(numbers, 300))
print(make_sum2(numbers, 300))
Interestingly they both give the same answer because your numbers are so small.
If you add a big number (like $100$) to the list, the results will be different.