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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Conway's Game of Life in 140 bytes Ruby

41 点作者 netmute超过 13 年前

7 条评论

tomstuart超过 13 年前
Off the top of my head, some simple ways to make this shorter:<p><pre><code> * Use 0...s*s instead of 0..s*s-1 * Use 0..s*s instead of 0...s*s (overrunning g doesn't matter much) * Use count{|x|x} instead of compact.count * Get rid of ||nil (because count{|x|x} ignores all falsy values) * Get rid of the brackets around g[i]&#38;&#38;n==2 * Use [g[i-s-1,3],g[i-1],g[i+1],g[i+s-1,3]].flatten instead of [[g[i-s-1],g[i-s],g[i-s+1],g[i-1],g[i+1],g[i+s-1],g[i+s],g[i+s+1]] * Use -1..s*s instead of 0..s*s and substitute i+1 for i (i.e. g[i+1] instead of g[i], but [g[i-s,3],g[i],g[i+2],g[i+s,3]] instead of [g[i-s-1,3],g[i-1],g[i+1],g[i+s-1,3]])</code></pre>
评论 #3580011 未加载
eddie_the_head超过 13 年前
And in APL:<p>life←{ ↑1 ⍵∨.^3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵ }
peteretep超过 13 年前
And in 131 characters of Perl: <a href="https://gist.github.com/1803656" rel="nofollow">https://gist.github.com/1803656</a><p>What do I win?
评论 #3579873 未加载
Cushman超过 13 年前
It's all ASCII... If you're using octets for each character, you can definitely still squeeze a few bytes out of that.
samwilliams超过 13 年前
Those interested in this post may like the examples on this page: <a href="http://codegolf.stackexchange.com/questions/3434/shortest-game-of-life" rel="nofollow">http://codegolf.stackexchange.com/questions/3434/shortest-ga...</a>
raganwald超过 13 年前
See also: <a href="http://willbailey.name/conway/docs/conway.html" rel="nofollow">http://willbailey.name/conway/docs/conway.html</a>
namidark超过 13 年前
None of these examples ran with 1.9.3 :\
评论 #3580984 未加载