Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
  • 14909989?s=100

    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.

  • 20051412?s=100

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

  • 14909989?s=100

    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

  • 20051412?s=100

    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.

  • 14909989?s=100

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

  • 18171520?s=100

    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.

  • 14909989?s=100

    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
  • Profile pic

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

  • 639336?s=100

    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
    
  • Profile pic

    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.

  • 639336?s=100

    @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 :)

  • Profile pic

    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).

  • Profile pic

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

  • 18171520?s=100

    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.

  • 21251044?s=100

    I made some edits:

    neigbourhood -> neighbourhood
    old men -> old man
    how to be a work -> how to work
    theyplay -> they play

    In initial solution: solution -> candyCount

    However, I agree with the other comments that the description could be clearer. I think it could stand to be edited a little more.

  • Loading more items...