Page 1 of 1

Population sum

Posted: September 14th, 2015, 6:03 pm
by gamnamno
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 ?

Re: Population sum

Posted: September 14th, 2015, 7:17 pm
by The Turtle
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.

Re: Population sum

Posted: September 14th, 2015, 8:34 pm
by flipper77
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

Posted: September 15th, 2015, 6:57 pm
by gamnamno
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.