Alexander Bass

Game of Life in Python

I’d like to show off the implementation of Conway’s Game of Life I made in Python. It’s a little unusual so please bear with me.

import time,os
from itertools import product as P
G=[[ord(os.urandom(1))<30for a in W]for b in H];B=G[:]
 G=[k[:]for k in B];print("\033c")
 for i in G:print(*map(lambda h:" █"[h]*2,i),sep='')
 for x,y in P(W,H):
  for X,Y in P(S,S):

It’s unreadable but at 383 bytes, the code runs the Game of Life. Run it in your terminal and it will show cells living and dying. I don’t blame you if you do not want to run random obfuscated code in your terminal, so you can instead try it below

How does one play the Game of Life? The rules are simple

  1. Start with a grid of square cells which can either be alive or dead
  2. At each cycle, check each cell in grid
  3. Count alive neighbors for each cell
  4. If an alive cell has exactly 2 or 3 alive neighbors it remains alive, otherwise it dies.
  5. If a dead cell has exactly 3 alive neighbors it becomes alive, otherwise it remains dead.
  6. Draw the grid with alive cells contrasting dead cells.
  7. Repeat cycle

I’ll leave it up to you to figure out how the code works.