7 ms·
Conway's Game of Life in 140 bytes Ruby
- peteretep 15y agoAnd in 131 characters of Perl: https://gist.github.com/1803656 https://gist.github.com/1803656 What do I win?
- peteretep 15y agoActually, what I /really/ won was the happy feeling I got from abusing $a and $b even though it runs under strict.
- tomstuart 15y agoOff the top of my head, some simple ways to make this shorter: * 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]&&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]])
- elitheeli 15y agoI really should have refreshed the comments page before shortening... seems like we think similarly: https://gist.github.com/1803557 https://gist.github.com/1803557
- Cushman 15y agoIt's all ASCII... If you're using octets for each character, you can definitely still squeeze a few bytes out of that.
- deleted 15y ago[deleted]
- namidark 15y agoNone of these examples ran with 1.9.3 :\
- netmute 15y agoOP here. I'm pretty sure they run in 1.9.3 because I wrote them in it.
- raganwald 15y agoSee also: http://willbailey.name/conway/docs/conway.html http://willbailey.name/conway/docs/conway.html
- eddie_the_head 15y agoAnd in APL: life←{ ↑1 ⍵∨.^3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵ }
- samwilliams 15y agoThose interested in this post may like the examples on this page: http://codegolf.stackexchange.com/questions/3434/shortest-game-of-life http://codegolf.stackexchange.com/questions/3434/shortest-ga...