![]() X and y co-ordinates in the -2 GB to 2 GB range (i.e. This is where most of the hard work and performance challenges are.įor this challenge, you don't need to be truly infinite, but you must handle cells with tick() - create the next generation of the Organism by applying the four rules above.get_live_cells() - return the list of all cells currently alive in the Organism.This is used for verification by unit tests. count() - return the number of live cells in the Organism.This is used to set the starting state of the Organism. insert_cells() - insert a list of live cells (x and y coordinates) into the Organism.If you want to test yourself, and have a few hours to spare, you might like to haveĪ go (without reading my solutions below) at implementing the above algorithm as a I'm interested to see how others go about it. ![]() Having spent time analysing this problem, My Perl solution is essentially a translation of the one I wrote first in C++. Including some profiling and performance optimization of my C++ solution. Though still a game of life novice, I've spent quite a bit of time on these solutions already. I wrote a couple of solutions myself, in both Perl and C++11, which I present below. How to implement it cleanly, concisely, efficiently. Not the GUI stuff, just the guts of the code. Rather than a chore, I actually found it very interesting. I've recently been forced to become acquainted with Conway's Game of LifeĪfter being asked to assess various implementations of it submitted by job applicants. The rules continue to be applied repeatedly to create further generations. The first generation is created by applying the above rules simultaneously to every cell in the seed -īirths and deaths occur simultaneously, and the discrete moment at which this happens is sometimesĬalled a tick (in other words, each generation is a pure function of the preceding one). The initial pattern constitutes the seed of the system. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.Any live cell with more than three live neighbours dies, as if by overcrowding.Any live cell with two or three live neighbours lives on to the next generation.Any live cell with fewer than two live neighbours dies, as if caused by under-population.The universe of Conway's Game of Life is an infinite two-dimensional orthogonal grid of square cells,Įach of which is in one of two possible states, alive or dead.Įvery cell interacts with its eight neighbours, which are the cells that are horizontally,Īt each step in time, the following transitions occur:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |