Ad
  • Custom User Avatar

    Math.sign(size % 4) will return '0' if size is a multiple of 4 and '1' if it is not.
    For the case if size is a multiple of 4, I just want to invert 1 and 0 in array one time less (see the picture prior to the solution - sust the case: 3 elements to be inverted).
    - 1 + Math.sign(size % 4)
    Hereby, this will give -1 to size/2 if the size is a multiple of 4 and nothing (-1 + 1) if not.

    // How can I explain this idea? I cannot. I remember that I just drew some variants on paper and came to this idea empirically...

  • Custom User Avatar
  • Custom User Avatar

    So, the problem with invalid chars existing in the test data still persists. I've tried a number of ways to get past this and it looks like it's on the test side and not mine. To give you an idea, at one point I was able to pass one of the real world tests by appending 3 nulls to the end of the string, which matches what I found in the infix passed to me. The next test failed with nulls mixed in at other positions.

    This is really frustrating. I've spent more time debugging problems with the test code than with my own.

  • Custom User Avatar

    This usually indicates a segfault (with C++ on CW). I printed the ascii of the input, and there are null characters (ASCII 0) in the input for the "real" test cases. I added an if to ignore these and any non-digit/non-operator/non-parenthesis, but I'm still getting a segfault (I guess), too.

  • Custom User Avatar

    You have received this error?
    If yes, I've got the same problem.

    // solution: virtual void POSTFIX::TESTS(): Assertion `to_postfix(infix) == postfix' failed.