% Monte-Carlo Search Algoritm on low-autocorrelation program
% BSDLicence
% Rick van der Zwet - 0433373 - <hvdzwet@liacs.nl>

% Brute-force result of length 20
% best_20 = [-1,1,1,-1,-1,-1,1,1,-1,1,-1,-1,-1,1,-1,1,1,1,1,1];
% autocorrelation(best_20);


best_fitness = 0;
while (1)
    % Generate a random column s={-1,1}^n
    n = 20;
    s = rand(n,1);
    s = round(s);
    s = s - (s == 0);

    % Find whether we are better than everything else
    fitness = autocorrelation(s);
    if (fitness > best_fitness)
        best_result = s;
        best_fitness = fitness
        % Little hack to display output nicely
        disp(rot90(best_result,-1));
    endif
endwhile

