Implementing a simple genetic algorithm