Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3309532
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:39:07+00:00 2026-05-17T21:39:07+00:00

Using PHP or Python , but I’m sure the basic functions are agnostic. I

  • 0

Using PHP or Python, but I’m sure the basic functions are agnostic.

I am unsure what the proper term, mathematical theory, or algorithm is, otherwise I’m sure Google would have fixed this for me in minutes.

I have a data set 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” row, based on these qualifiers:

  • cost: lower is better.
  • qty: higher is better.
  • ppl: lower is better.
  • store: Doesn’t matter in this case, but used later to find “best” depending on ‘store’.

Essentially, I’m trying to find the best particular “deal” in a “group buy”-like situation, where the fewest amount of people are required to get the best “value” (quantity -vs- cost).

To my eye, it appears that the best-overall would be Row #5, because of the jump in quantity.

If there is a name for this, and a good (Wikipedia?) article on the subject, I’d be happy to finish this myself. Thanks for your time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:39:08+00:00Added an answer on May 17, 2026 at 9:39 pm

    Compute qty / (cost * ppl) and sort the list by that number. This number will be higher for higher qty and lower cost and ppl.

    You might want to use something like this (python):

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

    Explanation: think what happens if qty is getting bigger when cost * ppl are constant. The ratio will increase, because a/x > b>x if a > b. Now with the other two values it’s the other way around; if x/a > x/b, then a < b, so the ratio would actually get decreased when cost or ppl increases (think what happens if you split 100$ to two people vs three people; if you split it to two, each will get 100/2 = 50$. If you split it to three, each will get 100/3 ~= 33$, which is less). (Sorry if i’m not making it clear enough; i’m tired)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've developed some web-based applications till now using PHP, Python and Java. But some
I'm thinking of switching from using PHP to Python for web applications, but I
im using eclipse for python but i dont know for php.. how can i
Using PHP to try and tackle this problem, but open to other solutions (Python,
I am confused about using php or python for implementing server program . I
I'm using a simple Python script to POST files to a PHP script: ...
i am currently using php as backend language in webdevelopment. but im wondering what
I have been using PHP for a while, but now I am trying to
I am trying to activate my virtualenv using a php script or a python
Using PHP, Perl, or Python (preferably PHP), I need a way to query an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.