Skip to content

Instantly share code, notes, and snippets.

@christabor
Created February 26, 2018 05:01
Embed
What would you like to do?
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