Ad
  • Custom User Avatar

    OP solved it, closing.

  • Custom User Avatar

    It's impossible to read such code blocks, especially large ones - the best practice is to post using markdown so it is readable:

    Read here how to use the Codewars markdown for posting comments

    Also, since C isn't the most popular language on site, if you don't get a reply rapidly your best bet would be to ask in Codewars Discord (there is a dedicated help-solve channel and a dedicated C channel).

  • Custom User Avatar

    Hi; as a general comment - on Codewars the "example tests" are on small input sizes; this is to allow you to troubleshoot your logic, make sure you understood the kata requirements etc.

    When you press Attempt, you will be tested against a (potentially very large) number of random tests on larger inputs - this will typically ensure that unoptimized brute force approaches time out.

    If your code works well but times out on Attempt, then you have found a working approach but not an efficient one - you need to optimize and/or redesign your approach.

    Since I don't use C/C++, I can't comment 100% on your current solution; but if the find instruction works by scanning through the entire string then your approach seems like it is O(n1 * n2 => n^2) to me where n1 and n2 are the sizes of the 2 strings.

  • Custom User Avatar

    your solution contains undefined behavior (UB). it will randomly fail depending on the configuration of memory at the time your function is called. in check_begin_zeros(), you are iterating backwards on the input strings, stopping when you find a nul byte. what guarantees you that there will be a nul byte in memory before the start of the string ? if there isnt one, you will keep looping on the memory located before the string in memory.

    because of the very nature of C and UB it is not possible for the tests suite to check if your solution contains UB. this is not a kata issue.

  • Custom User Avatar

    Translating from OP's to English: tests for C seem to be incomplete because OP's solution fails one sample test with leading zeros (the cr_assert_str_eq(strsum("00001", "9"), "10");), but still passes random tests. Random tests for C probably have to be hardened to prevent incomplete solutions from passing.

  • Custom User Avatar

    I guess you tried your code in your IDE outside CodeWars, and there you should call your function not once, but more than once like it is tested here:

        cr_assert_str_eq(strsum("123" , "456"),"579"); // first call to your function
        cr_assert_str_eq(strsum("00001", "9"), "10");  // second call to your function
        cr_assert_str_eq(strsum("00000", "0"), "0");   // third call to your function
    

    If you call it that way, you'll get a different value for the second test, instead of "10"

  • Custom User Avatar

    Your solution has a bug, it does not work correctly for inputs longer than 100 digits.

    Bug in your solution is not a kata issue.

  • Custom User Avatar

    C is not my cup of tea, but did you try calling your function several times in a row? Commenting out the first sample test, the second one, works. The third one fails tho no matter what, so, that looks like a problem with your code, and not a kata issue.

    Read this: https://docs.codewars.com/training/troubleshooting/#works-but-no

  • Custom User Avatar
  • Custom User Avatar

    Having the code formatted would be really helpful.

  • Custom User Avatar

    I am stuck with the same issue: "double free or corruption (out)". Were you able to solve this?

  • Custom User Avatar

    Language is C, and your code also fails regularly on some random tests (though not always). It's probable your function has some default somewhere and that it writes out of a regularly allocated space. This is a very common error in C (just search this on Google and you will see), it's impossible to answer you without more elements.

  • Custom User Avatar

    Which language?

  • Custom User Avatar
  • Custom User Avatar