Best formula for this case?

58 Views Asked by At

I have a programming assignment that asks me to create a block that is built off of components a, b, c, d, and e. The ideal block will have:

  1. Equals amounts of "a" and "b".
  2. Equal amounts of "c" and "d".
  3. When "c" and "e" are added together, they will equal "a".

I must create a function that forces inputs a, b, c, d, e to follow the constraints above. So, for example, if the inputs to my function were: 20a, 25b, 10c, 15d, 3e...

Then, one of the possible output would be: 20a, 20b, 10c, 10d, 10e.

Another possible output would be: 25a, 25b, 10c, 10d, 15e.

What do you think is the best formula or general strategy I could employ to make this work? Think of edge-cases. For example, what is the best thing to do if "c" was larger than "a"? Since "c" and "e", when added, need to make up "a", this is important (assume no negative numbers allowed... there needs to be "something" of "e").

Keep in mind this is a programming project.

Thank you.

1

There are 1 best solutions below

17
On BEST ANSWER

Here's an interesting one:

$a(n+1)=\frac{a(n)+c(n)+e(n)}2$

$b(n+1)=\frac{a(n)+3b(n)}4$

$c(n+1)=\frac{d(n)+3c(n)}4$

$d(n+1)=\frac{a(n)+d(n)-e(n)}2$

$e(n+1)=\frac{b(n)-c(n)+e(n)}2$

Note that when $n=0$, we use our initial values. As you keep looping this, it will approach a set of values that satisfy the problem without reaching the solution immediately.