Skip to content

Instantly share code, notes, and snippets.

@glv
glv / gist:1438719
Created December 6, 2011 16:05 — forked from gvaughn/gist:1436816
Conway's Game of Life in functional ruby
def evolve(generation)
live_neighbor_stats = generation_stats(generation)
live_neighbor_stats[3] + (live_neighbor_stats[2] & generation)
end
def generation_stats(live_cells)
live_cells.each_with_object(Hash.new(0)) {|live_cell, counter|
neighbors(*live_cell).each {|neighbor| counter[neighbor] += 1 }
}.each_with_object(Hash.new {|h,k| h[k] = []}) {|(cell, count), collector| collector[count] << cell}
end
@glv
glv / gist:134881
Created June 23, 2009 22:11 — forked from objo/gist:134796
entries.map(&:job).sort_by(&:number).map(&:project).compact.uniq