Population sum

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

Population sum

Post by gamnamno » September 14th, 2015, 6:03 pm

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 ?

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

Re: Population sum

Post by The Turtle » September 14th, 2015, 7:17 pm

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

Post by flipper77 » September 14th, 2015, 8:34 pm

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

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

Re: Population sum

Post by gamnamno » September 15th, 2015, 6:57 pm

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.

Post Reply