Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Yep. https://www.bell-labs.com/usr/dmr/www/cman.pdf
If p is NULL then it is falsy; and the && operator uses lazy evaluation, if its left operand is false, the expression evaluates to false without actually running the evaluation of the right operand. The same thing is true for the || operator as well, if the left operand is true, it returns true without trying to evaluate the right operand.
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.
there needs to be
3
live cells for a dead cell to become alive.2
is not enoughWhy 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?
The expected output you've listed is wrong as well. The actual expected output for that test is:
I could be wrong, but it looks like you are progressively changing the input, and that is causing errors as your process each cell. Everything in the universe happens all at once for each generation, what happens in one cell for the next generation shouldn't effect what happens in the next cell for that current generation.
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?
You return an array - a pointer to an array. When it is empty you can return NULL.
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.
Wow. I can't even follow this.
This is a good example of the tradeoff between speed/memory with this solution using very little memory. Well done.
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!
the Queue elements are pointers (
void*
) but you are storingint
egers instead. You need to take the address with&
when you enqueue, and dereference with*
when you dequeue. see my fork of your solutionc:
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.
This comment is hidden because it contains spoiler information about the solution