5 ms·
When I did a GOL demo (for my own pleasure because: why not?)[1] I quickly got frustrated by the idea that you need a 2D array to store the current state, and a
by rikroots 5y ago
When I did a GOL demo (for my own pleasure because: why not?)[1] I quickly got frustrated by the idea that you need a 2D array to store the current state, and a second array for the next state. My thinking was that we only need to know the index positions of the live cells (row * width + col) which can be stored in a 1D array. Identifying neighbour state then resolves into checking whether the currentState array includes the index of the neighbour cell (== alive).
I have no idea whether this approach is more, or less, efficient - but it was an interesting thing to model. Sadly I would've failed the Reddit interview because getting to that solution took me 3-4 hours; I was still fighting with 2D arrays at the end of the first hour.
[1] - https://codepen.io/kaliedarik/pen/BaLdwer https://codepen.io/kaliedarik/pen/BaLdwer
- dekhn 5y agowhen I hire I'm looking for folks who spend hours exploring, not the person who finds a local optimum fastest. Failing these sorts of interviews is not a sign you aren't a good programmer.