Skip to content(if available)orjump to list(if available)

Ask HN: What's the best implementation of Conway's Game of Life?

Ask HN: What's the best implementation of Conway's Game of Life?

98 comments

·February 12, 2025

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

This one is quite interesting:

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

It was also featured on HN:

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

tombh

I think "quite interesting" is an understatement. This is the Game Of Life simulating the Game Of Life. I personally consider it to be one of the Great Wonders of software.

orblivion

You know one of the hard questions here must be, what configuration exactly is it simulating? It has to be a configuration that simulates the same Game of Life at a higher scale. Any change you make to the configuration must also change the higher level configuration that it simulates.

And it occurs to me, a blank sheet of paper qualifies as the Game Of Life simulating the Game Of Life.

zamadatix

What makes GoL in GoL somewhat magical feeling is less "there are layers of logic being executed" and more "GoL rules and conditions are extremely restrictive yet still just complex enough to simulate nested execution of the ruleset itself". When you move up the complexity chain to "person with a sheet of paper" you lose some of that wonder to just end up with "extremely complex system can throw away most of the complexity to also simulate execution of a simple system" which feels a lot less surprising.

Pyrodogg

You might like this puzzle.

https://adventofcode.com/2024/day/21

It really makes you think about this; interaction between levels in a simulation.

thatguysaguy

If you think about it, that's basically what's going on if someone does a quantum mechanics simulation.

null

[deleted]

randomcatuser

Now that you say it like that...

What are other Great Wonders of software?

randomcatuser

1. Game of life simulating itself 2. Lisp interpreter (in C? or in Lisp) 3. a game engine?? 4. Bitcoin 5. Other distributed systems?? (Spanner?) 6. AI/deep learning representative. GPT4? AlphaGo? Pikadditions? 7. ?

jakemanger

Zooming out on that one is an absolutely amazing experience

cancerhacker

I made that a slowly panning and enlarging Mac OS screensaver from that site - 10 lines of source I’ve long since lost to load a web view. [edit to make sense]

planckscnst

You can also zoom in

ethanjstark

Beautiful. Looks like what I'd see when I would press on my closed eyeballs.

Within 30 seconds, it crashed my 2016 MacBook Pro (maybe overloaded the CPU + the failing battery? It's a feeble machine).

After the Mac's version of the BSD, Mac helpfully restored all of my windows (I have that setting turned off), and there it was again, happily Game Of Lifing in the background. Shut it down just as the fans were spinning up again.

teekert

This one is like looking the universe into its soul.

Btw, can the game of life (at least in theory) simulate chaotic systems like a double pendulum?

occamschainsaw

Cellular automata in general can exhibit chaos

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

AndrewOMartin

It's Turing complete, it can simulate anything any other Turing equivalent machine (e.g. a PC) can.

thymine_dimer

Next time I'm discussing the ol' "are we part of a simulation?" dilemma, I'll pull this up

disillusioned

Also the obligatory link to "I Don't Know, Timmy, Being God is a Big Responsibility" by qntm:

https://qntm.org/responsibilit

s-lambert

The Futurama episode "All the Way Down" and the visual novel Anonymous;Code have the same premise, it's a fun one.

kinderjaje

This is one of the best demos of Game of Life. I guess its just looping, and not all the movements are calculated, since you can zoom out till infinity?

Correct me if I am wrong.

berikv

This should be my new screensaver

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

zeroq

Even thought I know it has been developed in 1960 I always felt like it was specifically designed for making "twitter implementations" of things. ;)

yiyus

Alternatively,

    life←{≢⍸⍵}⌺3 3∊¨3+0,¨⊢

dang

An HN classic!

Conway's Game Of Life in APL (2009) [video] - https://news.ycombinator.com/item?id=22845249 - April 2020 (13 comments)

Conway's Game of Life in One Line of APL (2007) - https://news.ycombinator.com/item?id=10366441 - Oct 2015 (12 comments)

Conway's Game Of Life in APL - https://news.ycombinator.com/item?id=7492585 - March 2014 (2 comments)

Conway's Game Of Life written in one line of APL - https://news.ycombinator.com/item?id=4642628 - Oct 2012 (2 comments)

Conway's Game of Life in APL - https://news.ycombinator.com/item?id=4611015 - Oct 2012 (1 comment)

Conway's Game Of Life in one line of APL - https://news.ycombinator.com/item?id=3840273 - April 2012 (2 comments)

Conway's Game of Life in one line of APL - https://news.ycombinator.com/item?id=2547655 - May 2011 (22 comments)

Conway's Game of Life in one line of APL - https://news.ycombinator.com/item?id=1499630 - July 2010 (1 comment)

Conway's Game Of Life in one line of APL - https://news.ycombinator.com/item?id=1041500 - Jan 2010 (31 comments)

Game of Life implemented in 5 minutes using APL (amazing video) - https://news.ycombinator.com/item?id=451951 - Jan 2009 (1 comment)

Conway's Game of Life in one line of APL - https://news.ycombinator.com/item?id=451923 - Jan 2009 (1 comment)

Conway's Game of Life in one line of APL - https://news.ycombinator.com/item?id=204042 - May 2008 (4 comments)

---

Honorable mention:

Conway's Game of Life in APL in Forth - https://news.ycombinator.com/item?id=31537648 - May 2022 (25 comments)

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.

teraflop

FWIW, Golly (mentioned elsewhere in this thread) implements Hashlife as one of its core algorithms. So you can use it to simulate enormous patterns at enormous speeds, as long as they are sparse and/or regular enough that the hash hit rate is high.

https://golly.sourceforge.io/

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/

rasulkireev

i stared at this with more intensity and interest than any movie in the recent times

oneeyedpigeon

This is such a good way of presenting code-golf — well done!

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...

drpossum

Why is this the best one? Or is it just an implementation you like?

Jaxan

What would “best” even mean? There is no absolute criterium the test for.

drpossum

Agreed. The premise of this topic can't solicit a reasonable response, but you offered one anyways, hence my confusion.

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...

jakemanger

That is a great resource. I also love seeing it with ascii characters

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.

drpossum

Why is this the best one?

bryukh

For me, because of the algorithm and implementation, plus they have clients for different platforms with open-source code. Plus you can explore other cellular automatas.

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)

jakemanger

Seems like that's a favourite of almost everyone!

zabzonk

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

https://golly.sourceforge.io/

jakemanger

oooh the 3d implementation looks very cool

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!

jakemanger

Have fun with it! The continuous version leads to much more "living" creatures and different looking creatures as the world is more detailed and complex. It's also a bit more complex than the OG grid system implementation. There's so many variants out there to try (3d ones are my other favourite)

petters

Is it possible to implement a “glider gun” in 3D? (With reasonable rules) That was an open question a while ago