Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is how i would do it :</p> <ol> <li><p>First, i would just sort the teams based on their points. As you said, that is kinda trivial.</p></li> <li><p>Then, i would traverse the sorted array and check possible teams that have the same points. This would show in a new array of hashes. For each set of teams that i would find that have the same points, i would denote with a hash. Think of 3 competing teams :</p></li> </ol> <blockquote> <pre><code>{ :TeamA =&gt; 3, :TeamB =&gt; 2 } { :TeamA =&gt; 3, :TeamC =&gt; 4 } { :TeamB =&gt; 1, :TeamC =&gt; 0 } </code></pre> </blockquote> <ol> <li>Now, i would sort. To make things easy, you can have a max or min element (representing a team each time). </li> </ol> <p>Traversing with max :</p> <pre><code>1. max = TeamA 2. max = TeamC </code></pre> <p>So strongest team is TeamC. Eliminate that team and repeat. The last 2 hashes are now eliminated and we are just left with the first, which shows that TeamA > TeamB. So, the final sorting would be :</p> <p>TeamC > TeamA > TeamB</p> <p><strong>NOTICE</strong>: TeamC is not better than TeamB when only these two are regarded. This algorithm gives an overall better team, based on the winning points.</p> <p>Your case is actually simpler. You just want to compare two teams. Therefore, a hash like :</p> <blockquote> <pre><code>{ :TeamA =&gt; 3, :TeamB =&gt; 2 } </code></pre> </blockquote> <p>clearly denotes that TeamA is better than TeamB and should be ranked higher. If you want to compare 3 teams having the same points, you would have to have another criteria, like highest scoring team is better.</p> <p><strong>EDIT</strong></p> <p>If the next 2 factors to get the best team is goals scored and then lost difference, you would have another hash like :</p> <pre><code>{ :TeamA =&gt; [3, 2], :TeamA =&gt; [2, 1], :TeamC =&gt; [1, 1] } </code></pre> <p>With [3,2] indicating [goals scored, lost difference]. You can now easily identify the best teams based on these two parameters.</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