5 kyu

Sports League Table Ranking

109 of 584cshw89

Description:

Note: There is a harder version (Sports League Table Ranking (with Head-to-head)) of this.

Description

You organize a sports league in a round-robin-system. Each team meets all other teams. In your league a win gives a team 2 points, a draw gives both teams 1 point. After some games you have to compute the order of the teams in your league. You use the following criteria to arrange the teams:

  • Points
  • Scoring differential (the difference between goals scored and those conceded)
  • Goals scored

First you sort the teams by their points. If two or more teams reached the same number of points, the second criteria comes into play and so on. Finally, if all criteria are the same, the teams share a place.

Input

  • number: Number of teams in your league.
  • games: An array of arrays. Each item represents a played game with an array of four elements [TeamA,TeamB,GoalA,GoalB] (TeamA played against TeamB and scored GoalA goals and conceded GoalB goals ).

Output

  • positions: An array of positions. The i-th item should be the position of the i-th team in your league.

Example

number = 6
games = [[0, 5, 2, 2],   // Team 0 - Team 5 => 2:2
         [1, 4, 0, 2],   // Team 1 - Team 4 => 0:2
         [2, 3, 1, 2],   // Team 2 - Team 3 => 1:2
         [1, 5, 2, 2],   // Team 1 - Team 5 => 2:2
         [2, 0, 1, 1],   // Team 2 - Team 0 => 1:1
         [3, 4, 1, 1],   // Team 3 - Team 4 => 1:1
         [2, 5, 0, 2],   // Team 2 - Team 5 => 0:2
         [3, 1, 1, 1],   // Team 3 - Team 1 => 1:1
         [4, 0, 2, 0]]   // Team 4 - Team 0 => 2:0

You may compute the following table:

Rank Team For : Against GD Points
1. Team 4 5 : 1 +4 5
2. Team 5 6 : 4 +2 4
3. Team 3 4 : 3 +1 4
4. Team 0 3 : 5 -2 2
4. Team 1 3 : 5 -2 2
6. Team 2 2 : 5 -3 1

Team 5 and Team 3 reached the same number of points. But since Team 5 got a better scoring differential, it ranks better than Team 3. All values of Team 0 and Team 1 are the same, so these teams share the fourth place.

In this example you have to return the array [4, 4, 6, 3, 1, 2].

Fundamentals
Algorithms
Arrays
Sorting

More By Author:

Check out these other kata created by cshw89

Stats:

CreatedDec 31, 2019
PublishedDec 31, 2019
Warriors Trained2131
Total Skips44
Total Code Submissions5154
Total Times Completed584
Java Completions109
JavaScript Completions256
Ruby Completions37
Python Completions198
C# Completions19
Total Stars76
% of votes with a positive feedback rating90% of 123
Total "Very Satisfied" Votes104
Total "Somewhat Satisfied" Votes13
Total "Not Satisfied" Votes6
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • cshw89 Avatar
  • Avanta Avatar
  • hobovsky Avatar
  • Glyxerine Avatar
  • brodiemark Avatar
Ad