Ad
  • Custom User Avatar

    Apparently 'groupBy' is supposed to keep the order of the input data. But with 'orderBy' entries with the same key should get a different order? That makes no sense in my opinion. What is the logic that 'scientific' must be before 'teacher'?

    var persons = [
      {name: 'Peter', profession: 'teacher', age: 20, maritalStatus: 'married'},
      {name: 'Michael', profession: 'teacher', age: 50, maritalStatus: 'single'},
      {name: 'Peter', profession: 'teacher', age: 20, maritalStatus: 'married'},
      {name: 'Anna', profession: 'scientific', age: 20, maritalStatus: 'married'},
      {name: 'Rose', profession: 'scientific', age: 50, maritalStatus: 'married'},
      {name: 'Anna', profession: 'scientific', age: 20, maritalStatus: 'single'},
      {name: 'Anna', profession: 'politician', age: 50, maritalStatus: 'married'}
    ];
    
    Test.assertSimilar(query().select(professionCount).from(persons).groupBy(profession).orderBy(naturalCompare).execute(), [["politician",1],["scientific",3],["teacher",3]]);
    
  • Custom User Avatar

    Do you get a timeout? Then you may need to optimize your code. Otherwise I tried to debug my code by printing the table with Rank, Team, For, Against, GD, Points like in the description. Maybe this could be helpful.

  • Custom User Avatar

    The output should be an array of ranks for each team, not an array of teams for each rank. So the array [4, 4, 6, 3, 1, 2] means that the rank of Team 0 is 4, the rank of Team 1 is also 4, ..., the rank of Team 5 is 2.
    A team, which has not played yet, got 0 points, 0 goals scored and 0 goals conceded. But with these stats the team can still be ranked.

  • Custom User Avatar
  • Custom User Avatar

    I check again the performance of my code. The solution runs in only 430ms. The major portion of the runtime is in the setup of the tests (3.5sec). If your code runs in a timeout it means that your code is 20 times slower than the reference solution. In my opinion this is not tolerable.

  • Custom User Avatar

    I am fair enough to reduce the big tests to 15.

    But I run some performance tests and I got this results:

    my / your (in ms): 42 / 500, 28 / 568, 44 / 832, 45 / 760, 23 / 622

    In my opinion the difference is too big. I analysed your code and the problem is teamX = z.find( ({team}) => team===teamX ). You search the team in your team array for every single game (~300000 times). I modified your code. Before games.reduce I buffered the teams in an array to accessing the teams by an index. Now I passed all tests with the modified code.

  • Custom User Avatar

    This was not my intention. But I didn't optimized my code at all and it runs in 4 seconds. I didn't think the performance could be a problem. Can you post your solution as spoiler?

  • Custom User Avatar
    • expected/actual are swapped in example_random_single

    • solution setup is incorrect (contains Java/JS comment syntax)

    Your are right. I fixed it.

    every parts (solution setup, sample tests, test cases) contain commented out ruby code. Those should just be removed

    What do you mean? I don't see any comments in the parts expect of some # end x.

  • Custom User Avatar

    Ups, you are right. They should be 0:0. I fixed it.

  • Custom User Avatar

    I found it difficult to describe this rule. The term 'tie-breaker rule' is a good point. I copy the term 'Head-to-head' from here https://en.wikipedia.org/wiki/Group_tournament_ranking_system#Tiebreaker_criteria. But i didn't mention 'tie-breaker rule'. I rewrite this part of the description. Is it better to understand?

  • Custom User Avatar
  • Custom User Avatar

    I added some small examples. Is that better?

  • Custom User Avatar

    You are right. I fixed it.

  • Custom User Avatar

    Team 11 reaches 2 points because of the win. The teams 5, 6 and 10 got only 1 point (1 draw). Hence team 11 have to be ranked at the 5th place alone.

  • Custom User Avatar

    You are right. Probably I was too focused on this sentence. I thought there is a reason for that. The no-recursive test would be much easier :).

  • Loading more items...