Note that there are some explanatory texts on larger screens.

plurals
  1. POCode Golf: Conway's Game of Life
    text
    copied!<p><strong>The Challenge:</strong> Write the shortest program that implements John H. Conway's <em>Game of Life</em> cellular automaton. [<a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" rel="noreferrer">link</a>]</p> <p><strong>EDIT:</strong> After about a week of competition, I have selected a victor: <strong>pdehaan</strong>, for managing to beat the Matlab solution by <em>one</em> character with perl.</p> <p>For those who haven't heard of Game of Life, you take a grid (ideally infinite) of square cells. Cells can be alive (filled) or dead (empty). We determine which cells are alive in the next step of time by applying the following rules:</p> <ol> <li>Any live cell with fewer than two live neighbours dies, as if caused by under-population.</li> <li>Any live cell with more than three live neighbours dies, as if by overcrowding.</li> <li>Any live cell with two or three live neighbours lives on to the next generation.</li> <li>Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.</li> </ol> <p>Your program will read in a 40x80 character ASCII text file specified as a command-line argument, as well as the number of iterations (N) to perform. Finally, it will output to an ASCII file out.txt the state of the system after N iterations.</p> <p>Here is an example run with relevant files:</p> <p><strong>in.txt:</strong></p> <pre><code>................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ..................................XX............................................ ..................................X............................................. .......................................X........................................ ................................XXXXXX.X........................................ ................................X............................................... .................................XX.XX...XX..................................... ..................................X.X....X.X.................................... ..................................X.X......X.................................... ...................................X.......XX................................... ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ </code></pre> <p>Iterate 100 times:</p> <pre><code>Q:\&gt;life in.txt 100 </code></pre> <p><strong>Resultant Output (out.txt)</strong></p> <pre><code>................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ..................................XX............................................ ..................................X.X........................................... ....................................X........................................... ................................XXXXX.XX........................................ ................................X.....X......................................... .................................XX.XX...XX..................................... ..................................X.X....X.X.................................... ..................................X.X......X.................................... ...................................X.......XX................................... ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ </code></pre> <p><strong>The Rules:</strong></p> <ul> <li>You need to use file I/O to read/write the files.</li> <li>You need to accept an input file and the number of iterations as arguments</li> <li>You need to generate out.txt (overwrite if it exists) in the specified format</li> <li>You <strong>don't</strong> need to deal with the edges of the board (wraparound, infinite grids .etc)</li> <li>EDIT: You <strong>do</strong> need to have newlines in your output file.</li> </ul> <p>The winner will be determined by character count.</p> <p>Good luck!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload