Ad
  • Default User Avatar

    there is an empty test block Candy count with no assertions in it in the full tests, which therefore looks like a failed test

  • Custom User Avatar

    Extra challenge:

    • use object oriented programming

    No. Please, just no. Remove the last part.

    You might as well ask people to "use functional programming" to finish the kata. It's a pointless buzzword.

  • Custom User Avatar

    I would agree wholeheartedly that the best way to filter unoptimized programs is to run a ton of cases and cases with high n.

  • Custom User Avatar

    There is a rough way of determining time complexity though: Because time complexity is asymptotic, once input is sufficiently big you can test how the runtime scales with input size.

    Or, of course, you can just make really huge inputs and perform a stress test with time/memory constraint. Then the subpar algorithms will be choked to death :P

  • Custom User Avatar

    Time complexity is not determined by a test. It's generally determined by a human.

    Your time complexity is determined by how many loops you need to do and what you do in each loop. If you do a loop over an array once, you have O(n). If you loop over an array for each element in the array, you have O(n^2). Sorting an array with quicksort usually takes O(nlogn) (log base 2), but bubble sort takes O(n^2). Generally, pick the average case, but there are situations in which you want to report the worst case.

  • Custom User Avatar

    I wasn't talking about the tests, I was talking about the solutions. See my solution.

  • Custom User Avatar

    Have you read the tests? He's taken care of passing time. (Though there may be a bug on 29 Febrary and 31 August, October and December.)

    I don't think the description and the tests are that confusing.

    There could be more testing with separators other than /, but all in all I don't think it should not have been approved.

  • Custom User Avatar

    Wait, how did this got approved?

    • Description is confusing: These are separated by at least 1 character, but can be more, so anything can be inside, but by how the example is listed it looks like that only those few are valid
    • Example tests are even more confusing: should work with xxx followed by a date in the past which returns false? The individual test description are not really descriptive of the test in question either
    • In general, it's not a good idea to make a kata that relies on time, because then solutions get invalid as time passes
  • Default User Avatar

    Good call. I corrected it. Should be fine now.

  • Custom User Avatar

    kids are not "playing together" in your performance tests:

    function candyCount(kids, actions) {
      console.log({kids, play: actions.filter(x => x > kids)});
      // ommitted
    }
    
    // Basic tests
    // { kids: 5, play: [ 8 ] }
    // { kids: 7, play: [ 9, 9, 9 ] }
    // { kids: 1, play: [ 2, 3, 2, 8, 2, 2 ] }
    
    // Random tests
    // { kids: 65, play: [ 67, 66, 66, 67, 66, 67 ] }
    // { kids: 98, play: [ 99, 99, 99, 99 ] }
    
    // Performance tests
    // { kids: 296, play: [] } // For 157550 acts (length of actions array) and 296 kids
    // { kids: 101, play: [] } // For 119526 acts (length of actions array) and 101 kids
    // { kids: 769, play: [] } // For 179617 acts (length of actions array) and 769 kids
    // { kids:   n, play: [] } // ... for all test cases
    
  • Default User Avatar

    Thanks. I added test as suggested by @myjinxin. I wasn't sure how to make Codewars time out as @kazk said. I run ir few times, and I think I found a time limit that should work for some obvious mistakes.
    I will be happy for more feedback on it.

  • Custom User Avatar

    @pw108, maybe the most accurate way to test for time complexity better than O(N*M) is to design some test with N and/or M large enough so that O(N*M) solution takes longer than the time allowed by CodeWars.

    @myjinxin2015, I've been thinking that your performance measurement code can be improved, but had low priority because I know you fix issues very quickly and haven't seen complaints.
    I'm mainly concerned with the use of Date to measure small milliseconds and testing each call's execution time. I think using process.hrtime([time]) and testing execution time for n calls will be better.
    I might make a suggestion comment in one of your performance katas if I find time to write in more detail :)

  • Default User Avatar

    I actually not sure how to test for time complexity. I read the documentation on Test, but couldn't find any reference to it. I would really appreciate help with it.

    One could be tempted solve the problem by interagating through each time when the kids play, and fill the whole array with max. That would make it O(N*M). But it can be done O(N+M).

  • Default User Avatar

    Thanks. Sorry for the spell check.... and also for making it clearer.

  • Custom User Avatar

    I've tried fixing it up a bit more.

    One should really only read from "for simplicity .." to "the goal is .."; the rest is quite unessential, though a nice story.

  • Loading more items...