From: Joey Date: 2006-05-15T03:29:58+09:00 Subject: Re: Conway's Life de-golfed ------=_Part_24376_27684464.1147631396149 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thanks alot Mike, I was the one who started that thread, and wrote most of the basic code. Even though I wrote it, I couldn't deobfuscate it afterwards! Is it ok if I pop this on my site? http://code.eachmapinject.com/game_of_life_golf.rb j`ey http://www.eachmapinject.com On 5/14/06, Mike Nelson wrote: > > I took some golfed code from a discussion here little while back ( > http://www.ruby-forum.com/search?query=3DGolfing+a+signature.&forums%5B%5= D=3D4 > ) and tried my hand at de-golfing and re-working it a bit to make it > readable. > > There are some things here that are a little clumsy, I think. I'm > wondering if there are other things that I might do to it to make it > even more readable. Any ideas? > > > Cell_Set, Cell_Clear =3D "#", " " > Line_Range =3D 0...20 > before =3D Line_Range.map {Line_Range.map {(rand<0.7) ? Cell_Set : > Cell_Clear}} > > Neighbors =3D [] > (-1..1).map do |x| > (-1..1).map do |y| > Neighbors << [x,y] unless x=3D=3D0 && y=3D=3D0 > end > end > > puts "\e[2J" # clear screen > save =3D nil > until save =3D=3D before do > puts "\e[H" # go 'home' > puts before.map {|x| x.join(" ")} * "\n" > save =3D before.map {|x| x.dup} > before =3DLine_Range.map do |x| > Line_Range.map do |y| > count =3D (Neighbors.map do |n| > dx, dy =3D x+n[0], y+n[1] > if Line_Range=3D=3D=3Ddx and Line_Range=3D=3D=3D= dy > before[dx][dy] > else > Cell_Clear > end > end - [Cell_Clear, nil]).size > count=3D=3D2 ? before[x][y] : (count=3D=3D3 ? Cell_Set : > Cell_Clear) > end > end > sleep 0.1 > end > > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_24376_27684464.1147631396149--