Created
October 15, 2014 17:38
-
-
Save tjoskar/6d372d3cdc1e666911b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time, os | |
size = 25 | |
b = [[0 for x in xrange(size)] for x in xrange(size)] | |
a = [[0 for x in xrange(size)] for x in xrange(size)] | |
b[10][10] = 1 | |
b[11][11] = 1 | |
b[11][10] = 1 | |
b[10][11] = 1 | |
b[2][1] = 1 | |
b[3][1] = 1 | |
b[4][1] = 1 | |
b[5][1] = 1 | |
b[1][2] = 1 | |
b[5][2] = 1 | |
b[5][3] = 1 | |
b[1][4] = 1 | |
b[4][4] = 1 | |
def create_new_bord(b): | |
b_prime = [[0 for x in xrange(size)] for x in xrange(size)] | |
for x in xrange(1, len(b)-1): | |
for y in xrange(1, len(b)-1): | |
n = b[x-1][y] + b[x-1][y-1] + b[x-1][y+1] + b[x+1][y] + b[x+1][y+1] + b[x+1][y-1] + b[x][y-1] + b[x][y+1] | |
if b[x][y] == 1 and (n < 2 or n > 3): | |
b_prime[x][y] = 0 | |
elif n == 3 and b[x][y] == 0: | |
b_prime[x][y] = 1 | |
else: | |
b_prime[x][y] = b[x][y] | |
return b_prime | |
def print_b(): | |
for x in xrange(len(b)): | |
a[x] = [1 if e == 1 else ' ' for e in b[x]] | |
print('\n'.join([''.join(['{:4}'.format(item) for item in row]) | |
for row in a])) | |
def cls(): | |
os.system(['clear','cls'][os.name == 'nt']) | |
while True: | |
print_b() | |
b = create_new_bord(b) | |
time.sleep(0.3) | |
cls() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment