Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2025-04-17 15:28:14

RegJose
Novice
Registered: 2025-04-10
Posts: 8

Proportional that doesn't reduce the lowest values

If I have a limit of 3000 for the sum of some values and I have some values like [3500, 900, 500, 200, 50], how can I use a proportional that takes into account the specific weight of each value with respect to the rest so that, in practice, it hardly reduces the value 500 and does not reduce the values 200 and 50.

Offline

#2 2025-04-17 23:50:14

Bob
Administrator
Registered: 2010-06-20
Posts: 10,736

Re: Proportional that doesn't reduce the lowest values

There are many questions I would want to ask before tackling this problem.
Such as "What happens if the order total is already less than 3000?"
"If we classify the order items as large order medium order and small order then what is the largest value that makes a small  , what is the smallest value that makes a large and hence we know the range for  medium?"
"What if a type is out of stock?"

I'll assume the 5 types are already in ascending order of size. If not you need to perform a sort routine to get them in order


Let's call the five numbers c1, c2, c3, c4, and c5.

The final values will be d1, d2, d3, d4 and d5
.

By your rules d4 = c4 and d5 = c5.

To reduce c3 by a small amount use the formula

d3 = c3 x (3000 - d4 - d5) x 1.5 /(c1 + c2 + c3)

1.5 here was an arbitrary choice that works for these values.
It would be better if the amount to reduce was given more precisely.


With your values that makes 420 after rounding down.

d3 + d4 + d5 = 670 so c1 + c2 must be reduced to 2330

d1 = c1 x 2330/4900 and d2 = c2 x 2330/4900

4900 here is the current total and 2330 is the target total.

Those values come to1853 and 476 after rounding down.

The grand total is 2990 because of the rounding so you need a line that says while total < 3000 add 1 to d3.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#3 2025-04-18 10:09:36

RegJose
Novice
Registered: 2025-04-10
Posts: 8

Re: Proportional that doesn't reduce the lowest values

I appreciate your help. This is the visual way to make the smallest values complete. Visually, we see that the last three values are lower, so we include them completely, and distribute the remaining space proportionally among the larger values.

If all the values are lower than the limit, then they are all completely included.

But I'm wondering if there's a formula or C function that detects the disproportionality between the large values and the small ones and applies a proportional value that will subtract more from the large values and little or nothing from the small ones.

For example (invented values), if the largest value is 3500, a proportional reduction of 1.8 could be applied based on its "weight" relative to the rest of the values. For the value 900, a proportion of 1.3, for 500, 1.1, and for the rest, nothing.

Offline

#4 2025-04-18 23:57:52

Bob
Administrator
Registered: 2010-06-20
Posts: 10,736

Re: Proportional that doesn't reduce the lowest values

What's missing is an exact definition of large  medium and small. Then a rule for medium reduction, say 60% of the large reduction.

I doubt C would have a specific routine for this as its too unusual. But a suitable formula could be made. I'd need the answers to the above questions


Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#5 2025-04-19 01:49:58

Bob
Administrator
Registered: 2010-06-20
Posts: 10,736

Re: Proportional that doesn't reduce the lowest values

I've made up some constraints to illustrate what I mean.

I'll define a large order as amount > 600
Medium as 250< amount < 600 including these endpoints
And small as amount < 250

If everything were to be reduced in the same proportion
then k = target amount / actual amount

But we want k for small to be 1, k for large to be sufficient to reach a total of 3000  and k for medium to be less than k for large.

I'll make k for medium to be 60 % of k for large.

This gives me a way to calculate k for large

The total for new large plus new medium is 3000 -200-50

So L.k + M - M(1-k)x0.6 = 2750

Rearranging k = (2750 - 0.4 x 500)/(4400 + 0.6x500)
= 0.54255...

Using this the new values are
1898,  488,  362,  200,  50 giving a total of 2998.

This is because I've rounded every calculation down.

So apply WHILE total < 3000 medium = old medium + 1 so this loops until 3000 is reached.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#6 2025-04-19 10:54:41

RegJose
Novice
Registered: 2025-04-10
Posts: 8

Re: Proportional that doesn't reduce the lowest values

I appreciate your help. Your formula requires defining large, medium, and small. It's like paying taxes in brackets. Those who earn between X and Y will pay 30%...

I'm thinking about finding a way to compare values so I can define how large a value is compared to the others, so I can apply a reduction in that proportion. So, the "largest" values would reduce the most, the "intermediate" ones would reduce the least, and the "lowest" values would not reduce at all.

We can do it visually; why can't we do it mathematically?

Offline

#7 Yesterday 04:48:36

Bob
Administrator
Registered: 2010-06-20
Posts: 10,736

Re: Proportional that doesn't reduce the lowest values

Please would you post the original assignment


Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

Board footer

Powered by FluxBB