You need to sign in or sign up before continuing.×
5 kyu

Sports League Table Ranking (with Head-to-head)

15 of 38cshw89
Description
Loading description...
Fundamentals
Algorithms
Arrays
Sorting
Performance
  • Please sign in or sign up to leave a comment.
  • dfhwze Avatar

    You allow mutation of input to interfere with test cases.

  • JohanWiltink Avatar
    Passed: 53 Failed: 0 Exit Code: 1
    Test Results:
    Solution
    example1
    example2
    example3
    exampleEmpty
    exampleOneGame
    exampleCrazy
    exampleRandomAlmostEmpty (5 of 5 Assertions)
    exampleRandomManyShare (20 of 20 Assertions)
    exampleRandomFull (20 of 20 Assertions)
    exampleRandomBig (2 of 2 Assertions)
    

    Is it your intention to force performance to the point where I can't write a nice, structured, functional solution with lots of object constructuring and destructuring?

    ETA: Node 10 is faster; I get 10/20 through Random Big.

    • cshw89 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?

    • JohanWiltink Avatar

      This comment has been hidden.

    • cshw89 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.

    • cshw89 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.

    • JohanWiltink Avatar

      Then there should probably be a performance tag.

    • JohanWiltink Avatar

      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.

      I mostly just have zero interest in solution performance. I aim for correctness and simplicity ( and find({team}) => team===teamX was gloriously simple :), and I have compilers to optimise things and hardware to accelerate them. ( Also, if I'm processing 300 000 games, I'm willing to wait a little. The waiting won't ever take as long as those games did to play. :P ) Your opinion is of course as good as mine ( and actually better on your kata. :)

      Question marked resolved by JohanWiltink 5 years ago
    • cshw89 Avatar

      Ok, I added it.

    • dfhwze Avatar

      I agree with Johan on this one. The performance constraints are tedious. Also, when adding performance constraints you should at least have a section in the description describing those constraints.

  • SQSCWQ Avatar
    28 [ [ 0, 27, <2 empty items> ],
      [ 1, 26, <2 empty items> ],
      [ 2, 25, <2 empty items> ],
      [ 3, 24, <2 empty items> ],
      [ 4, 23, <2 empty items> ],
      [ 5, 22, <2 empty items> ],
      [ 6, 21, <2 empty items> ],
      [ 8, 6, <2 empty items> ],
      ... 278 more items ]
    

    There are empty items as input in exampleRandomCrazy test

  • dinglemouse Avatar

    I found the description was hard to understand.

    Yes, the example is clear, and yes, the text makes sense in hindsight, but the meaning of "Head-to-head" fooled me for a very long time.

    I think root of my confusion was you put "Head-to-head" in same bullet list with other comparator criteria

    And saying stuff like this made it sound like it was similar to others

    Finally, if all criteria are the same...

    Whereas (IMO) the "head-to-head" is different. It's more like "special tie-breaker rules" quite unlike the other comparator criteria.

    If it wasn't in that list, and if there was another title (e.g. "Head-to-head tie-breaker rules") I think I would have finished this Kata a few hours sooner!

    (Or perhaps I am wrong and just solved this in a clumsy way).