Skip to content

Instantly share code, notes, and snippets.

from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
def circle(distance):
return lambda point: (point.x ** 2. + point.y ** 2.) ** (1/2.) < distance
def offset(region, position):
return lambda point: region(Point(x=point.x-position.x, y=point.y-position.y))
@antoniojrossi
antoniojrossi / chromosomes.rb
Created July 1, 2011 19:33 — forked from jfcalvo/chromosomes.rb
A simple function to generate random chromosome strings
# 72.217263 seconds generating 10.000.000 chromosomes
def generate_chromosome_1(length, alleles)
(1..length).collect { alleles[rand(alleles.size)] }.join
end
# 64.619006 seconds generating 10.000.000 chromosomes
def generate_chromosome_2(length, alleles)
chromosome = String.new
for i in 1..length