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 ?

## Population sum

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

### Re: Population sum

Like this?
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.

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)
```

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.

### 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))
```

### 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.