Skip to content

Instantly share code, notes, and snippets.

View shetharp's full-sized avatar

Arpit Sheth shetharp

View GitHub Profile

Conway's Game of Life is a "zero player game" consisting of a 2D grid of cells, which can be on or off ('alive' or 'dead'). The entire grid transitions from one state to another according to the following rules:

  • For each cell, count how many of its eight neighbors are alive.
  • If a live cell has fewer than two live neighbors, it dies as if from underpopulation.
  • If a live cell has more than three live neighbors, it dies as if from overpopulation.
  • If a dead cell has exactly three live neighbors, it becomes alive as if from reproduction.
  • Otherwise, cells remain in their current state.

For example, if you start with a pattern like:

@shetharp
shetharp / polaroid-colors-hex.js
Last active August 10, 2020 06:31
Polaroid Color System
const colors = {
white100: "#FFFFFF",
white80: "hsla(0, 0%, 100%, 0.8)",
white50: "hsla(0, 0%, 100%, 0.5)",
white20: "hsla(0, 0%, 100%, 0.2)",
flash100: "#EEEEEE",
flash80: "hsla(0, 0%, 93%, 0.8)",
flash50: "hsla(0, 0%, 93%, 0.5)",
flash20: "hsla(0, 0%, 93%, 0.2)",
@shetharp
shetharp / conways-game-of-life.py
Created February 6, 2020 01:02
Conway's Game of Life
exampleGrid = [
[0, 0, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0],
]
def getNeighborIdx(i, j, size):
"""Returns a list of indexes to visit that are not out of bounds given the grid size"""
neighbors = []