Ad
  • Custom User Avatar

    Yes, I initially assumed global variables because this is one of the most common cause of complaints about "works for me but not here", and additionally I misunderstood the "there is exact single input and exact single output" part. Only later I checked your solution and found actual bug.

  • Custom User Avatar

    You did not initialize your coordinates array

    Ooh, dam… Yeah, I haven't coded in C++ for quite a while, I was absolutely sure arrays work like vectors in terms of pre-initialization (vectors are initialized to default values). Thank you!

    This is wrong, because if there is 10 basic tests, Codewars run all 10 of them

    You still misunderstood me here: I did copy all 10 of the tests, that's the main point of confusion.

    The problem here (with uninitialized values) are the compiler settings. Although, it is still weird that I'm not seeing this, because I'm running locally with -fsanitize=address,undefined, so I should've gotten a warning about uninitialized values. Weird…

  • Custom User Avatar

    It's impossible to "run them differently", at least not by mistake. There nothing to "run differently", there is exact single input and exact single output.

    This is wrong, because if there is 10 basic tests, Codewars run all 10 of them. If you run only one of them locally, you will not detect issues like, for example, use of stale values of global/static variables (I am not saying that this is your problem, but it's one of the reasons when users complain that their solution works locally, but not on CW).

  • Custom User Avatar

    Specifically for cases like this one, when users blame their problems on the platform instead on their own code, I ceated a bot which helps beginners. I run it on your solution and it said:

    Here's what I found:

    You did not initialize your coordinates array, so the starting values of xy[0] and xy[1] are undefined. This means your function can return incorrect results because you are comparing uninitialized values at the end. This is a very common mistake in C++ when using plain arrays.

    Initializing variables before use is crucial, especially with primitive types or fixed-size arrays.

    PS. I usually try to avoid spoilers when supporting users but this bug might be indeed difficult to reproduce, and I think it's worth to close the argument sooner than later)

  • Custom User Avatar

    Sorry, there seems to be misunderstanding. Let me clarify: the task has "basic" and "random" tests. There are 10 "basic" tests, and you can copy them. The tests are just "run function with exact input and compare to the expected output". That is to say:

    Problem is how you run your solution locally, because you run it differently than the site

    It's impossible to "run them differently", at least not by mistake. There nothing to "run differently", there is exact single input and exact single output.

  • Custom User Avatar

    what I see here is that site result is different from my result on the same input, which is a problem with the site.

    This is not a valid conclusion, but it's very often made by beginners. Problem is how you run your solution locally, because you run it differently than the site. What you need to try is to run your solution more than once for different inputs.

  • Custom User Avatar

    I mean, I have copied "basic tests" and ran them locally. They all return the expected results. There may be a flaw in my solution, but what I see here is that site result is different from my result on the same input, which is a problem with the site.

  • Custom User Avatar

    The site doesn't run code like that.

    Your code has a different flaw you have not yet detected.

  • Custom User Avatar

    There seems to be a bug: after sending solution it says no tests are passing, but then if I copy the "basic tests" and run with the same code on my computer, I get the answers tests expect. It would seem like site has cached my wrong code (I had mistakenly used a == b == c in C++, forgot it doesn't work that way there, changed to a == b && a == c), and despite it showing the correct code it apparently runs the older incorrect version…?

  • Custom User Avatar

    Please, don't post solutions in Discourse. Already told you that, didn't I?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Merged.

  • Custom User Avatar

    C Fork

    addresses this and other testing concerns

  • Custom User Avatar

    Actual and expected are switched in assertion messages in C.

  • Custom User Avatar

    Oh, found my error and sorted it out! Thanks for the help

  • Loading more items...