For example, I have this data:
headings = { :heading1 => { :weight => 60, :show_count => 0} :heading2 => { :weight => 10, :show_count => 0} :heading3 => { :weight => 20, :show_count => 0} :heading4 => { :weight => 10, :show_count => 0} } total_views = 0
Now I want to serve each heading based on their weights. For example, for the first 10 queries / iterations, heading1 , heading3 , heading2 and heading4 will be serviced 6, 2, 1 and 1 times, respectively, in order (by weight).
For each iteration, the show_count of the served header will increase by one, and total_views will also increase worldwide.
Could you suggest an algorithm or some ruby ββcode to handle this.
source share