Search for the best "deal" in the "group purchase", given the table of values

Using PHP or Python , but I'm sure the core functions are agnostic.

I’m not sure what the correct term is, mathematical theory or algorithm, otherwise I’m sure that Google would have installed it for me in a matter of minutes.

I have a dataset similar to the following:

cost | qty | ppl | store
------------------------
   30|  500|   10|     1
   40|  600|   12|     2
   35|  500|   14|     3
   50|  700|   10|     1
   30|  700|   12|     1
   40|  250|   14|     2

What I'm trying to do is find the “optimal” string based on these qualifiers:

  • cost: lower is better.
  • qty: higher is better.
  • ppl: lower is better.
  • store: does not matter in this case, but is used later to find the "best" depending on the "store".

, "" " ", "" ( -vs-cost).

, , Row # 5 - .

(?) , . !

+3
3

qty / (cost * ppl) . qty cost ppl.

, - (python):

def cmp(a, b):
    return (a["qty"] / (a["cost"] * a["ppl"])) - (b["qty"] / (b["cost"] * b["ppl"]))

list = sorted(list, cmp)

: , , qty , cost * ppl . , a/x > b>x, a > b. ; x/a > x/b, a < b, cost ppl (, , 100 , , 100/2 = 50 $. , 100/3 ~ = 33 $, ). (, , )

+5

- .

+1

, , , , qty, ppl / . .

, - , qty - , , ppl - , . * ppl/qty , , , , . , . , , qty , , . , , qty 4, # ppl 4. , cost ^ 2 ppl/qty. , - , ^ m ppl ^ n/qty ^ p, ; m, n, p ( ) , .

0
source

Source: https://habr.com/ru/post/1772724/


All Articles