TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Game of Life in all languages

7 pointsby luminaobscuraabout 13 years ago
If Hello World is inadequate, what canonical program would better serve to demonstrate the salient features of a programming language? ... One suggestion (from David Pearce) was Conway’s Game of Life: a simple simulation of finite automata. This seems like a good demonstration of most of the properties. http://ejrh.wordpress.com/2012/05/10/beyond-hello-world/

5 comments

tzsabout 13 years ago
I don't see a shell version, so below is mine (well...it is not strictly shell, as it uses sort, uniq, grep, sed, and comm). It's written as a filter that takes as input live cell coordinates (one cell per line, X and Y coordinates separated by white space), and outputs the live cells of the next generation.<p>For example, on this input:<p><pre><code> -10 100 -10 101 -10 102 1000 5 1001 5 1002 5 </code></pre> the output is:<p><pre><code> -11 101 -9 101 1001 4 1001 6 -10 101 1001 5 </code></pre> Here is the code, for bash or similar shells:<p><pre><code> &#62; alive.$$ while read cells do echo $cells &#62;&#62; alive.$$ set x $cells x=$2 y=$3 echo $x $((y-1)) echo $x $((y+1)) echo $((x-1)) $((y-1)) echo $((x-1)) $y echo $((x-1)) $((y+1)) echo $((x+1)) $((y-1)) echo $((x+1)) $y echo $((x+1)) $((y+1)) done | sort | uniq -c &#62; neighbors.$$ grep '^ *3' &#60; neighbors.$$ | sed -e 's/^ *[0-9].//' grep '^ *2' &#60; neighbors.$$ | sed -e 's/^ *[0-9].//' &#62; has2.$$ sort alive.$$ -o alive.$$ comm -12 has2.$$ alive.$$ rm has2.$$ neighbors.$$ alive.$$</code></pre>
luminaobscuraabout 13 years ago
If Hello World is inadequate, what canonical program would better serve to demonstrate the salient features of a programming language?<p><pre><code> Must it use variables? Must it have flow control? Must it actually compute something? Must it use non-primitive data structures? Must it exhibit use of the language’s code organisation features? </code></pre> These are some of the more generic properties that programs can have.<p>...<p>One suggestion (from David Pearce) was Conway’s Game of Life: a simple simulation of finite automata. This seems like a good demonstration of most of the properties.<p><a href="http://ejrh.wordpress.com/2012/05/10/beyond-hello-world/" rel="nofollow">http://ejrh.wordpress.com/2012/05/10/beyond-hello-world/</a>
DisposableMikeabout 13 years ago
Brainfuck? Erlang? Coldfusion? Visual Basic (6/.NET)? Those are just a couple right off the top of my head.<p>It is quite cool, though, to see a common problem solved in such a wide variety of languages.<p>s/all languages/lots of languages/g
willvarfarabout 13 years ago
The APL version is mindbendingly awesome: <a href="http://www.youtube.com/watch?v=a9xAKttWgP4" rel="nofollow">http://www.youtube.com/watch?v=a9xAKttWgP4</a> &#60;-- watch it!
luminaobscuraabout 13 years ago
clojure, f# and python seems very terse.