TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Game of Life in all languages

7 点作者 luminaobscura大约 13 年前
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 条评论

tzs大约 13 年前
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>
luminaobscura大约 13 年前
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>
DisposableMike大约 13 年前
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
willvarfar大约 13 年前
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!
luminaobscura大约 13 年前
clojure, f# and python seems very terse.