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?

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

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.

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/

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.

thatguysaguy

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

null

[deleted]

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

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.

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

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

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)

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

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/

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

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!

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.

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)

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.

zabzonk

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

https://golly.sourceforge.io/

jakemanger

oooh the 3d implementation looks very cool