Skip to content

Instantly share code, notes, and snippets.

@MicTech
Created April 29, 2014 10:59
Show Gist options
  • Save MicTech/11396875 to your computer and use it in GitHub Desktop.
Save MicTech/11396875 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var currentState = new bool[10,10];
var futureState = new bool[10,10];
currentState[0, 0] = true;
currentState[0, 1] = true;
currentState[1, 0] = true;
currentState[1, 1] = true;
currentState[2, 2] = true;
currentState[2, 3] = true;
currentState[3, 2] = true;
currentState[3, 3] = true;
while(true)
{
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
int count = 0;
for (int dx = -1; dx < 2; dx++)
{
for (int dy = -1; dy < 2; dy++)
{
if (dx == 0 && dy == 0)
{
continue;
}
try
{
if(currentState[x+dx,y+dy])
{
count = count + 1;
}
}
catch
{
}
}
}
if (currentState[x,y])
{
if (count < 2)
{
futureState[x, y] = false;
}
else if (count > 3)
{
futureState[x, y] = false;
}
else
{
futureState[x, y] = true;
}
}
else
{
if (count == 3)
{
futureState[x, y] = true;
}
}
}
}
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
Console.Write(futureState[x, y] ? '*' : ' ');
}
Console.WriteLine();
}
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
currentState[x, y] = futureState[x, y];
}
}
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
futureState[x, y] = false;
}
}
Console.Read();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment