forked from JustinLove/conwayslife
-
Notifications
You must be signed in to change notification settings - Fork 1
purplejacket/conwayslife
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
I wanted to find a little project to use as an interview prep for my friend Dan and found JustinLove's game of life. I separated the tests into a separate file so these could be used as a mock interview in which the tests are a given and the final implementation is what is arrived at. As with JustinLove's implementation, this program has no UI, it just manipulates the data structures. ORIGINAL VERSION OF THE README: This project was part of a random pair programming exercise at the 2009-11-03 ChicagoRuby meeting. The exercise was Conway's game of life. This version was completed by Justin Love and Dave Giunta in about two hours. What is particularly interesting about this implementation is that it actually operates on an infinite grid. In certain places (especially live checking) the performance will suffer considerably for this, although that that might be addressed with some refactoring. The basic strategy is a coordinate-indexed hash table of interesting cells. Cells are interesting if they have a neighbor. A version that addressed the expensive live-checks might also treat live cells as interesting in order to combine storage. The table is created by iterating over live cells and incrementing the neighboor count around them. Indexing the hash table by location allows you to have reasonable lookups of neighbor counts without allocating a finite grid. Things can only happen to live cells or those dead cells next to live cells, so the process of calculating the neighbor counts also creates a list of the cells that have to be considered for births/deaths. As a special case, the locations of live cells are not put into the table, so if it has no neighbors, it will not even be put into the hash table, and will 'die' by not being considered for the next generation.
About
Conway's Game of Life, from a two hour pair programming exercise with Justin Love and Dave Giunta
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- Ruby 100.0%