Note that there are some explanatory texts on larger screens.

plurals
  1. POpython: algorithm - to gather items from mean
    text
    copied!<p>Not sure whether this is the right place, but I have a question related to algorithm and I cant think of an efficient algorithm. So thought of sharing my problem statement.. :) To ease up what I am trying to explain, let me create a hypothetical example.</p> <p>Suppose, I have a list which contains an object whcih contains two things..</p> <pre><code>lets say product id and price </code></pre> <p>Now, this is a long long list..sort of like an inventory.. out of this I have defined three price segments.. lowprice, midprice and highprice and then k1,k2,k3 where k1,k2 and k3 are ratios. So, the job is now,, I have to gather products from this huge inventory in such a way that there is n1 products from lowprice range, n2 products from midprice range and n3 products from high price range... where n1:n2:n3 == k1:k2:k3</p> <p>Now, how do I efficiently achieve the following. I target the low price point is 100 dollars and I have to gather 20 products from this range.. mid price range is probably 500 dollars and so on</p> <p>So I start with 100 dollars.. and then look for items between 90 and 100 and also between 100 and 110 Let say I found 5 products in interval 1 low (90,100) and 2 products in interval 1 high (100,110) Then, I go to next low interval and next high interval. I keep on doing this until I get the number of products in this interval.</p> <p>How do I do this?? Also there might be case, when the number of products in a particular price range is less than what I need.. (maybe mid price range is 105 dollars...).. so what should I do in that case.. Please pardon me, if this is not the right platform.. as from the question you can make out that this is more like a debative question rather than the "I am getting this error" type of question. Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload