HACKER Q&A
📣 jakemanger

What's the best implementation of Conway's Game of Life?


Anyone else, like me, at one point try to implement Conway's Game of Life? If you have, what is the best implementation you've found?

Mine has to be this continuous version that makes pretty crazy looking creatures: https://chakazul.github.io/Lenia/JavaScript/Lenia.html.


  👤 selcuka Accepted Answer ✓
This one is quite interesting:

https://oimo.io/works/life/

It was also featured on HN:

https://news.ycombinator.com/item?id=39799755


👤 account-5
Has to be the APL implementation [0] purely due to how small and arcane it is:

    life ← {⊃1 ⍵ ∨.∧ 3 4 = +/ +⌿ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵}
The video runs you through it, even if it doesn't make it any clearer for non-apl'ers.

[0] https://aplwiki.com/wiki/Conway%27s_Game_of_Life


👤 mordechai9000
Not an implementation, but Bill Gosper's hashlife algorithm blew my mind when I first encountered it.

https://en.wikipedia.org/wiki/Hashlife

My personal favorite has to be the one I made in x86 assembly ~30 years ago. I didn't know about hash life at the time, but still, it ran pretty fast. I seem to remember I used page flipping and moved the start of video memory each iteration. Or something like that.


👤 pmc00
Code-golfed Game of Life in Javascript we wrote a while back with some friends. Always surprising how much abuse Javascript can take: https://shorterlife.github.io/challenge/

👤 twp
Game of life implemented as sets in Clojure:

(defn neighbors [[x y]] #{[(dec x) (dec y)] [(dec x) y] [(dec x) (inc y)] [ x (dec y)] [ x (inc y)] [(inc x) (dec y)] [(inc x) y] [(inc x) (inc y)]})

(defn count-neighbors [world cell] (count (set/intersection (neighbors cell) world)))

(def rules #{[true 2] [true 3] [false 3]})

(defn live [world cell] (contains? rules [(contains? world cell) (count-neighbors world cell)]))

(defn evolve [world] (into #{} (filter #(live world %) (reduce set/union (map neighbors world)))))

Full source: https://github.com/twpayne/life/blob/master/clojure/src/life...


👤 js2
Not sure if it's the best implementation, but Norvig's may be the best explanation:

https://colab.research.google.com/github/norvig/pytudes/blob...


👤 davidst
I wrote Qlife, a game of life "compiler" that generated X86 asm code, for one of Michael Abrash's optimization challenges in the early 90s.

Description: https://www.phatcode.net/res/224/files/html/ch18/18-01.html

Code: https://www.phatcode.net/res/224/files/html/ch18/18-03.html

Hashlife is far superior so while Qlife was interesting it wasn't the best implementation.


👤 bryukh
My favorite for anyone interested in cellular automata optimization is Golly (http://golly.sourceforge.net/). It uses the Hashlife algorithm, which can simulate enormous patterns by caching repeated blocks. While other implementations might be prettier, Golly's ability to run complex patterns at incredible speeds makes it the go-to for serious exploration.

👤 daemonologist
Depends on your metric, but this recursive one is pretty good: https://oimo.io/works/life/

Previously: https://news.ycombinator.com/item?id=39799755

(Ope, ninja'd)


👤 zabzonk
I've always liked Golly - covers all sorts of CAs.

https://golly.sourceforge.io/


👤 JoeDaDude
The best one is the one you make yourself. I made my first one using a BASIC compiler for the Timex Sinclair 2068. The compiler only supported 1-dimensional arrays and I used special characters so I could get 4 pixels in each alpha numeric character position. That required a lot of (for my age) clever programming but it worked so well, I would let it run for hours and just watch the patterns it produced.

👤 marshughes
Oh my god, I've been meaning to give Conway's Game of Life a shot for ages! Your post just gave me the final push. What makes the continuous version stand out? Are there any unique features in the rules that lead to those crazy - looking creatures? I'm all ears!

👤 mintycrisp
GoL is always so interesting and a lot of cool implementations here I haven't seen before. I made a 3D on a 2D board version a while back in Web XR with A-Frame that turned out pretty neat if anyone wants to check it out --> https://mintycrisp-a-frame-game-of-life.glitch.me/

👤 failrate
Rudy Rucker has Capow, which is pretty great continuous CAs: https://www.rudyrucker.com/capow/

👤 quuxplusone
Circa 25 years ago, I spent a lot of time with my (Borland Turbo C, Mode 13h) implementation that was just a vanilla Game of Life, but depicted as a red-to-blue heatmap. Every time a cell changed state, it'd become R gradations redder; every time it didn't change state, it'd become B gradations bluer. This produces a visualization where the background "space" is a uniform blue, blinkers are hot red hollow diamonds, and the actually interesting chaotic parts are appealingly fuzzy shades of reddish purple. Because it takes a while for a cell to "heat up," a glider can be almost invisible, depending on how you choose the constants R and B.

I'm not saying this is mechanically interesting (it's just a simple filter) or will change your life or anything, but I do remember spending a lot of time tinkering with and watching that particular implementation.



👤 thesuperbigfrog
Best by what criteria?

Best looking? Lowest resource utilization? Smallest code size? Fastest? Largest playing field? etc.


👤 pthyme
Game of life in many languages, benchmarked, by my brilliant former co-worker Eric: https://github.com/ericnewton/many-lives/tree/master

👤 c0nstantine
I have a minimalistic one (7 lines in Python) using convolutions:

https://c0stya.github.io/articles/game_of_life.html

### The code ###

  import numpy as np
  from scipy.signal import convolve2d

  field = np.random.randint(0, 2, size=(100, 100)) # 100x100 field size
  kernel = np.ones((3, 3))
  
  for i in range(1000): # 1000 steps
      new_field = convolve2d(field, kernel, mode="same")
      field = (new_field == 3) + (new_field == 4) * field

👤 nneonneo
This infinitely recursive Game of Life by saharan is pretty dang cool: https://oimo.io/works/life/


👤 vintermann
I remember there was an old C programming textbook which used game of life as an introduction to basic data structures and algorithms, going from lists of live cells to hashmaps etc. It was more focused on teaching basic programming than the game of life itself, so it stopped short of HashLife, but I think it had at least three increasingly sophisticated implementations.

Maybe someone on HN remembers it and can tell me its name?


👤 nonrandomstring
There was this one that ran on networked SGI Indigos, tiling an X Display for screensaver on each workstation so the whole lab came alive as this insane petri-dish of things flying around the room.

👤 joeld42
The one that had the most personal influence on me was the chapter from Michael Abrash's Graphics Programming Black Book: https://www.phatcode.net/res/224/files/html/ch17/17-01.html#...

CPU are very different these days, but the process he goes through is essentially unchanged.


👤 zamalek
It might be argued that one of the dynamic programming (caching) ones would be the best by a reasonable standard. These can be used to simulate absolutely monstrous grids, and is where we see simulated CPUs and whatnot.

Here's the game of life running in the game of life: https://youtu.be/xP5-iIeKXE8?si=7NslTsVlW0USjQFw - that one uses Golly.


👤 topologie
I'm fond of this one, since a friend of mine, Carlos Pérez Delgado, worked on it: https://en.wikipedia.org/wiki/Quantum_cellular_automaton. :)

(In case it's not super clear, I'm kinda jokin' here...)


👤 petabyt
Surprised nobody has mentioned https://copy.sh/life/

👤 spcebar
I certainly can't claim it's the best, but I combined Conway's Game of Life and the falling sand game and I think it's neat. https://benergize.com/games/conways-game-of-life/

👤 o1nder
Made this last week with the help of o1, it's hexagonal cells and you can adjust the rules for birth and survival.

https://chatgpt.com/canvas/shared/67a71a9f57bc819185cade8f59...


👤 lscharen
I thought that SmoothLife was fascinating when I found it.

At the time I was doing a lot of simulation work, so methods for bridging discrete and continuous domains were interesting.

https://github.com/duckythescientist/SmoothLife


👤 zabzonk
Unrelated to my other comment here - how to do life without an actual computer, an old blog of mine:

https://latedev.wordpress.com/2011/06/25/a-poker-chip-comput...


👤 kmoser
I wrote one in 6502 (ok, 6510) assembler for the C-64 several decades ago, which included the ability to edit and save playing fields. I also wrote one in Excel using only formulas (no VBA). Neither of them were the "best" but they were great learning experiments.

👤 nickcw
I wrote one in 68000 assembly on my Atari ST which implemented the life rules using bitwise logic. That meant I could do 32 cells in parallel in a kind of primitive SIMD!

The most mind blowing algorithm has to be hashlife though. Well worth studying for those aha moments.


👤 cowboy_henk
Here's a nice continuous version that has multiple colors and parameters you can tweak. And it works in webgl: https://smooth-life.netlify.app/

👤 guinn8
I thought this implementation chatgpt O1 wrote for was visually appealing and fun in its simplicity.

https://guinn8.ca/conway.html

I like control-shift-r to refresh the page.


👤 dvh
The best game of life is reverse game of life: https://youtube.com/watch?v=g8pjrVbdafY

(may include SAT solvers and traces of black magic)


👤 vax425
I made this one to brighten up any office:

https://digitalhorology.etsy.com/listing/1644589175


👤 carabiner

👤 jimmaswell
Not strictly an answer, but I just started learning low-level CUDA and this gives me the idea to implement it there as an exercise. Certainly lends itself to parallelization.

👤 deadfoxygrandpa
this one is my own implementation in blender geometry nodes. i did it in only 10 nodes and i think it's interesting:

https://x.com/deadfoxygrandpa/status/1819204922271060440

screenshot of it here: https://i.imgur.com/Iq9XXi4.jpeg


👤 kalleboo
I wrote one complete with a GUI in yBasic on my Palm Vx when I was bored during lectures, to me that makes it the one that has given me the most value!

👤 ahuth
Obviously this TypeScript one: https://huth.me/conway4/

👤 OnionBlender
How do people update the grid? Do people use two grids and alternate them? Like double buffering in a game? Or is a grid a wrong representation?

👤 kfogel
Xlife

I believe it implements Bill Gosper's hashlife quadtree algorithm (already mentioned elsewhere in the comments here).

Xlife is unbelievably fast.


👤 mometsi
Most clever has to be the encoding on the left side of the flag of Belarus, which reveals a special pattern after 1991 iterations!

https://en.wikipedia.org/wiki/Flag_of_Belarus#/media/File:Be...

Edit: not really. But what a wasted opportunity. Come on, State Committee for Standardization of the Republic of Belarus, what are you doing all day?


👤 dang
(I did a bit of surgery on this post - I moved your text to the top and moved the link to the text so that the submission would show up on /ask. Then I put it in the second-chance pool (see https://news.ycombinator.com/item?id=26998308) so it will get a random placement on HN's front page. I hope this is all ok!)