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.

Conway's Game of Life in 140 bytes Ruby

41 pointsby netmuteover 13 years ago

7 comments

tomstuartover 13 years ago
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_headover 13 years ago
And in APL:<p>life←{ ↑1 ⍵∨.^3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵ }
peteretepover 13 years ago
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 未加载
Cushmanover 13 years ago
It's all ASCII... If you're using octets for each character, you can definitely still squeeze a few bytes out of that.
samwilliamsover 13 years ago
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>
raganwaldover 13 years ago
See also: <a href="http://willbailey.name/conway/docs/conway.html" rel="nofollow">http://willbailey.name/conway/docs/conway.html</a>
namidarkover 13 years ago
None of these examples ran with 1.9.3 :\
评论 #3580984 未加载