Ad
  • Custom User Avatar

    unreadable. imagine debugging the code of someone long gone and seeing this abomination 😀

  • Custom User Avatar

    unreadable. imagine debugging the code of someone long gone and seeing this abomination 😀

  • Custom User Avatar

    Using a Spell Checker, seems like "must be offset from startX and startY" is the right answer, thanks!

  • Custom User Avatar

    I am not a native English speaker so I could be wrong, but I believe it should be "offset", not "offsetted": "The coordinates passed to the perlin function must be offset from startX and startY"

  • Custom User Avatar

    Please see this article for some explanation and ideas, maybe something useful can be found there: https://docs.codewars.com/languages/c/authoring/memory-management-techniques

    The approach with memory allocated by a user solution and freed by tests is considered acceptable in Codewars kata and many users do not see anything wrong with it, so if you really want to use it for some reason, you can. However, I personally (as well as a couple of other users) do not like it and consider it bad, for a several reasons. Additionally, in context of this kata, allocation in solution is totally unnecessary. I would definitely prefer passing a preallocated buffer to user solution.

    You can use whichever approach you want, because Codewars allows both. I would recommend passing in a buffer allocated by caller, because I strongly believe that returning raw allocated pointer and passing its ownership is bad. Creating a deallocation function, as suggested by Donald, is arguably more complex than allocation by caller, but definitely better than free in tests. But the most important point is that whichever approach you choose, it has to be explicitly documented, either in language-specific paragraph in description, or in soluton template.

  • Custom User Avatar

    It's added :)

  • Custom User Avatar

    (if you (plural) finally go that way, you (singular) can use conditional rendering blocks to provide the info to C users without cluttering the description for others. See here )

  • Custom User Avatar

    As I really want the user to allocate the memory itself because it's an interesting part of the kata, why not keeping it like it's done actually (allocation in the function, free in the tests)? Also adding instructions that the user should allocate memory by itself.

  • Custom User Avatar
  • Custom User Avatar

    Yes, you should explicitly tell the user that they must allocate memory by themselves at the very least. But there is a bigger issue here: you aren't supposed to split the responsibility of memory management between the solver and the tests. Either you make the user perform all required memory management by themselves (including both memory allocation and deallocation), or you absolve the user of this responsibility entirely by managing it in the tests.

    For the former case (where the user allocates memory and cleans up after themselves), you should require the user to define a pair of functions: one for allocating required memory and computing the result, and one for deallocating whatever memory was allocated in the solution function, e.g.

    wchar_t *solution(...);
    void dealloc_solution(wchar_t *);
    

    And then in the tests, you invoke solution to obtain the result, perform any assertions required on the result and invoke dealloc_solution on the result to return the memory to the system.

    Of course, for this case you cannot guarantee that dealloc_solution actually performs the required cleanup: it is difficult if not impossible to test for absence of memory leak on Codewars. So the better solution is to have the tests manage all the memory by changing the function signature of the user solution as mentioned before, like so:

    void solution(..., wchar_t *out);
    

    In this case, you don't have to define a pair of functions. Instead, the solver assumes that out is some pre-allocated buffer (statically or dynamically, it does not matter) large enough to hold the result and writes the result to it directly. Then, in the tests, if out is dynamically allocated, it should be freed by the tests after performing required assertions to prevent memory leak.

  • Custom User Avatar

    I changed the description, how do you find it?

  • Custom User Avatar

    not really. You're relying on assumptions, there. An user could considere the origin is there, then y goes up, but he wants to fill the area below, and then you end up with an user putting some minus signs here and there. Just add the info, please. If you didn't wanna have to do all that, you should have used the usual 2D-array indexing (x vertical going down + y horizontal going left) ;p

  • Custom User Avatar

    Well we have "y is the vertical coordinate" and "{x=0, y=0} starts at the top-left", seems like it's fine like that?

  • Custom User Avatar

    almost: plz add the positive direction going down for y

  • Custom User Avatar

    It should be fine now

  • Loading more items...