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

  • 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.
  • And repeated random test also added...

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

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

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

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

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

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

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

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

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

  • Thanks for review.

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

  • size_t is only guaranteed to be in std.
    Corresponding headers should be included for std::size_t and std::pair.
    Random tests needed.

  • Loading more items...