%a=rand(2,12)
%cut = floor(11*rand)
%a(1, 1:2)
%b = [a(1,1:cut), a(2,(cut+1):11)]


number_of_genes = 400;
population_size =  40;
max_generation  = 120;

population = floor(2*rand(population_size, number_of_genes));
fitness = number_of_genes - (sum(population'))';
population(:,number_of_genes+1) = fitness;

population = sortrows(population, number_of_genes+1);
xx = [];
yy = [];

for time=1:max_generation
for j=1:population_size
   child = [];

   parent1 = population((floor((population_size/2)*rand)+1), :);
   parent2 = population((floor((population_size/2)*rand)+1), :);

   for n=1:number_of_genes
      which = floor(2*rand);
      if (which == 0)
         child(n) = parent1(n);
      else
         child(n) = parent2(n);
      end
   end

fitness = number_of_genes - (sum(child'))';
child(number_of_genes+1) = fitness;

population(j, :) = child;
population = sortrows(population, number_of_genes+1);
end

population(1, :);

xx(end+1) = time;
yy(end+1) = population(1,number_of_genes+1);
end

plot(xx, yy)
