Skip to content

Instantly share code, notes, and snippets.

@christabor
Created February 26, 2018 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christabor/3b0cffc517162ab286a4a9d0f3aeda55 to your computer and use it in GitHub Desktop.
Save christabor/3b0cffc517162ab286a4a9d0f3aeda55 to your computer and use it in GitHub Desktop.
plant type reproduction automata experiment
from random import choice
types = ['sporophyte', 'gametophyte']
class Plant(object):
def __init__(self, type=None):
self.type = type or choice(types)
self.children = []
def __repr__(self):
return '<Plant="{}">'.format(self.type)
def reproduce(self):
if self.type == 'sporophyte':
self.children.append(Plant(type='gametophyte'))
else:
self.children.append(Plant(type='sporophyte'))
def make_conditions():
plants = [Plant(), Plant()]
iterations = 20
while iterations > 0:
print('iteration={}'.format(iterations))
for p in plants:
p.reproduce()
for p in plants:
for child in p.children:
child.reproduce()
iterations -= 1
return plants
def show(plants):
for p in plants:
print(p)
for child in p.children:
print(' {}'.format(child))
for grandchild in child.children:
print(' {}'.format(grandchild))
if __name__ == '__main__':
plants = make_conditions()
show(plants)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment