%Krypto Solver
clear;

[num, ~,~] = xlsread('krypto.xls');


res = num(6);
inp = num(1:5);

sym = ['+', '-', '*', '/'];

permsn = perms(inp);
permss = combn(sym,4);

permsnsize = size(permsn);
permsnsize = permsnsize(1);

permsssize = size(permss);
permsssize = permsssize(1);
sol = '';
count = 1;

for i = 1:permsnsize
    for j = 1:permsssize
        out = eval([num2str(permsn(i,1)),permss(j,1),num2str(permsn(i,2)),permss(j,2),num2str(permsn(i,3)),permss(j,3),num2str(permsn(i,4)),permss(j,4),num2str(permsn(i,5))]);
        if out == res
            sol(count,:) = [num2str(permsn(i,1)),permss(j,1),num2str(permsn(i,2)),permss(j,2),num2str(permsn(i,3)),permss(j,3),num2str(permsn(i,4)),permss(j,4),num2str(permsn(i,5))];
            count = count + 1;
        end
    end
end
if count == 1
    msg = 'No Solutions Found!'
else
    msg = [num2str(count), ' solutions found']
    choice = input('View solutions? 1 = Yes, 0 = No');
    if choice == 1
        sol
    end
end

xlswrite('Solutions.xlsx', sol);
% plot(x,y,'or')
%text(x,y,cellstr(a),'VerticalAlignment','bottom', 'HorizontalAlignment','right')

% p = regress(y,x);
% plot(x, x*p)
% p = regress(y,[x x.^2]);
% plot(x, [x x.^2]*p)