## Population sum

For scripts to aid with computation or simulation in cellular automata.
gamnamno
Posts: 22
Joined: March 5th, 2014, 3:39 pm
Location: Rambaud, France
Contact:

### Population sum

Hi,
I need a way to calculate the sum of the populations from one step to another, which means the total number of cells that have lived in that time.
I have no Python knowledge so can anyone help me ?

The Turtle
Posts: 102
Joined: May 6th, 2015, 8:14 pm
Location: Chicago, Illinois

### Re: Population sum

Like this?

Code: Select all

``````import golly
cells = golly.getcells(golly.getrect())
sum = (len(cells) + len(golly.evolve(cells, 1))) / 2 # divide by 2 because there is both an x and y coordinate for one cell
golly.note("The population between this generation and the next is %d" % sum)
``````
A block therefore would output 8 and the r-pentomino would output 11.
Or do you not count repeated cells? e.g. a block would be 4 and the r-pentomino would be 7.
Only two things are constant: change and the speed of light.

flipper77
Posts: 197
Joined: October 24th, 2010, 3:25 am
Location: Spokane, WA

### Re: Population sum

This is one way of doing it:

Code: Select all

``````import golly as g

gens = 4
total = 0

for n in xrange(0, gens):
total += int(g.getpop())
g.run(1)

g.show(str(total))``````

gamnamno
Posts: 22
Joined: March 5th, 2014, 3:39 pm
Location: Rambaud, France
Contact:

### Re: Population sum

Thanks ! flipper77's script is what I was looking for. Sorry I wasn't very clear on the fact that it has to calculate the sum in multiple steps.