Ad
  • Custom User Avatar

    Okay thank you for clearing that up. That is super helpful. It looks like I didn't copy-paste from the test script. It's funny how you see things one way until someone says something.

  • Custom User Avatar

    Why does the top right cell not get upgraded to 1? It is has 2 "living" neighbors? I copy-pasted this expected 3x3 matrix directly from the test code. If the actual expected output for this test is as you say than the test code is wrong. Also - I don't update the next generation sequentially, but all in parallel in a new area called local_next, where the values are all determined by the current generation's cell data. I am still unclear why this 3x3 data doesn't grow to 4x4. The problem states that the space is infinite and that the areas outside the given grid are assumed to be 0. Are we not supposed to spawn new live cells in this area? If we are, than why should the area not grow? Specifically the bottom row has 2 1's. This should provide 2 locations - in the 4th row - where the assumed 0s become 1s. Is this not how the game works?

  • Custom User Avatar

    I don't think I am getting ho wthis is supposed to work. My code is taking this input

    1 0 0.

    0 1 1.

    1 1 0.

    And after 1 generation I have a 4x4 output (as some of the surrounding vlaues are brought to life).
    Here is my output after 1 generation

    0 0 1 1.

    1 0 0 1.

    0 1 1 1.

    0 1 1 0.

    However, the test is looking for a 3x3 output here.

    0 1 1.

    0 0 1.

    1 1 1.

    Which is not the complete next generation.
    Am I missing something?

  • Custom User Avatar

    You return an array - a pointer to an array. When it is empty you can return NULL.

  • Custom User Avatar

    I am having trouble with the c version. I pass the 3 tests, and when I "attempt" it either fails the first test or passes 6 tests and then fails with a message that it crashed. I think I may not be returning the right thing for the empty [[]] matrix. I have tried returning 0, NULL, and int *out where out is set to 0. What are you returning for this case?

    EDIT: I found the bug. Returning NULL for this case is fine. My bug was when I was allocating memory for the output vector I was using (cols)x(row) rather than (cols)x(rows), and row was a variable I had set to 0. It was working some of the time, probably overwriting unused memory or something, but then occasionally crashing it.

  • Custom User Avatar

    Wow. I can't even follow this.

  • Custom User Avatar

    This is a good example of the tradeoff between speed/memory with this solution using very little memory. Well done.

  • Custom User Avatar

    After looking at some of the other solutions I see how helpful the queue actually is. I think in my solution I could have skipped the queue and put it strait in the int array. Also I had tried putting the & infront of the node->value, but forgot to derefrerence on the way out so that is where I was really stuck. Thanks for the help!

  • Custom User Avatar

    c:

    I have submitted my solution, which passes all tests, but I am getting the following warnings.
    I am not sure how to use these external functions without generating these conversion warnings. Any advice?

    solution.c:45:20: warning: incompatible pointer to integer conversion assigning to 'int' from 'void *' [-Wint-conversion]
    sorted_tree[i] = queue_dequeue(queue);
    ^ ~~~~~~~~~~~~~~~~~~~~
    solution.c:76:34: warning: incompatible integer to pointer conversion passing 'const int' to parameter of type 'const void *' [-Wint-conversion]
    queue = queue_enqueue(queue, node->value);
    ^~~~~~~~~~~
    solution.c:16:56: note: passing argument to parameter 'data' here
    extern Queue *queue_enqueue (Queue *queue, const void *data);
    ^
    2 warnings generated.

  • Custom User Avatar

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