Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

this should do the trick...

  while creatures:
    c = get_random_creature()
    if c.is_dead():
      creatures.pop(c)
    else:
      creatures.add(c.mutate())


You also need selection, not just mutation (I know you are being silly, so am I)


Selection is handled by asynchronous events which populate the is_dead() boolean.

Critiquing my own code, though, it should really be a check against 'can_reproduce()' rather than 'is_dead()'.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: