From: Mike Nelson Date: 2006-05-15T00:15:32+09:00 Subject: Conway's Life de-golfed I took some golfed code from a discussion here little while back ( http://www.ruby-forum.com/search?query=Golfing+a+signature.&forums%5B%5D=4 ) 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 = "#", " " Line_Range = 0...20 before = Line_Range.map {Line_Range.map {(rand<0.7) ? Cell_Set : Cell_Clear}} Neighbors = [] (-1..1).map do |x| (-1..1).map do |y| Neighbors << [x,y] unless x==0 && y==0 end end puts "\e[2J" # clear screen save = nil until save == before do puts "\e[H" # go 'home' puts before.map {|x| x.join(" ")} * "\n" save = before.map {|x| x.dup} before =Line_Range.map do |x| Line_Range.map do |y| count = (Neighbors.map do |n| dx, dy = x+n[0], y+n[1] if Line_Range===dx and Line_Range===dy before[dx][dy] else Cell_Clear end end - [Cell_Clear, nil]).size count==2 ? before[x][y] : (count==3 ? Cell_Set : Cell_Clear) end end sleep 0.1 end -- Posted via http://www.ruby-forum.com/.