Ad
  • Custom User Avatar

    Approved some time ago

  • Custom User Avatar

    Can someone accept this? All issues are resolved...

  • Custom User Avatar

    There are few places, where CPU cycles are totally wasted.

    • prime_factors are executed for each element of the array twice
    • in prime_factors you don't need to count all factors - if cnt is greater then k, you can stop searching.
  • Custom User Avatar

    And repeated random test also added...

  • Custom User Avatar

    50 of what? Repeats?

    Random tests. (in a loop.) Prefferably 100 of them.

    I completely don't get the approach to random tests at codewars. IMHO it would be best to have fixed RNG seed and some number of randomized test cases - so they are random(ized) but repeatable.

    Well, you make a loop for 100 tests, generate a random number, and test the user's solution with it.

  • Custom User Avatar
  • Custom User Avatar

    @Steffan153 - 50 of what? Repeats?
    I completely don't get the approach to random tests at codewars. IMHO it would be best to have fixed RNG seed and some number of randomized test cases - so they are random(ized) but repeatable. (On my other solution, I was pointed, that fixed RNG seed is bad, because it's not random that way...).
    IMHO random test cases should test how the solution works on bigger dataset, that can't be easily hardcoded. All the corner/edge cases should be tested in normal tests.

  • Custom User Avatar

    I see what @Steffan153 means now. It's definitely better to include whatever is used explicitly.

    For example, the reference solution happens to work without including any of them, but it might break any time if something changes internally (like test framework). Same thing for the tests. It should include anything it uses even if it currently works.

    Also, it doesn't obfuscate the code at all.

  • Custom User Avatar

    It looks like it does work without <algorithm>.
    @Steffan153, can you explain why it's needed? Does anything in test uses it?

  • Custom User Avatar

    Does it continue to compile even if the solution removes the header? Tests should include whatever it requires independent from the solution.

    We need to consider the case where users come up with different ways to solve and removes unnecessary headers for their solution.

  • Custom User Avatar

    TBH there is no reason for more random tests - they will be basically the same.

    it seems pointless for me.

    How is it pointless? All random tests should have at least 50

    And regarding headers - everything compiles and executes correctly - why should I add headers that are technically unnecessary and only obfuscate the source code?

    Because it's bad practice...

  • Custom User Avatar

    And regarding headers - everything compiles and executes correctly - why should I add headers that are technically unnecessary and only obfuscate the source code?

  • Custom User Avatar

    Original task has no random tests.
    TBH there is no reason for more random tests - they will be basically the same. I can loop to test more than one strings, but it seems pointless for me.

  • Custom User Avatar

    Only 1 random test????
    Sample tests and tests need headers for std::pair, char, size_t, and std::vector.
    Tests need header <algorithm>, I think.

  • Custom User Avatar

    Thanks for review.

    Fixed all issues.
    Original task (Rust translation) has no random tests, but I added them for C++.

  • Loading more items...