1

For a database-frontend, I need to calculate a "score" from a multitude of different variables. While this in itself is rather easy, there is one smaller part that I can't figure out how to solve. The specifications are as following:

  1. The result must be a percentage value between 0% and 100%.
  2. Given is a set of [1,n] percentage values ([22%, 79%, 30%] for example).
  3. The percentages should have a positive effect on each other, but not in a way that they just sum up.
  4. The order of the percentages in the set must not matter.

Some examples:

  • [79%, 22%] => ~85%
  • [20%, 60%, 10%] => ~70%
  • [90%,90%] => 98%
  • [60%] => 60%
  • [25%] => 25%
  • [100%] => 100%
  • [20%, 100%] => 100%
  • [10%, 100%, 30%] => 100%
  • [75%, 0%] => 75%
  • [0%] => 0%

As a developer, I probably have a different approach for mathematics - it is a bit difficult for me to find the correct words to describe what I mean. If you need any further information, let me know! As the solution must written in code anyways, I am also open to pseudo-code or just steps to take.

I would be very happy about every idea - thanks in advance!

1 Answers1

2

Quick thought that may work.

For each percent $p$ in the original set (as a fraction between $0$ and $1$), calculate $q = 1-p$.

Let $Q$ be the product of all the factors $q = 1-p$.

Then return $1-Q$.

I think that does what you want and matches all your edge cases.

Ethan Bolker
  • 95,224
  • 7
  • 108
  • 199