Working genetic algorithm