function finalAnswer=solver(numPegs,numColors,guessLimit,puzzleID)
% By Fei Tang, IMEC, BELGIUM, tang@imec.be.
% Initialization
numCallsMade=0;
guess=ones(1,numPegs);
%color_set=1:numColors; % set of possible colors, initial value
[black_pre, white_pre, numCallsMade]=scoreme(guess,puzzleID);
color_set=2:numColors;
for i=1:numPegs
set_length=length(color_set);
index=logical(ones(1,set_length));
% tmp_set=[];
for count=1:set_length
guess_buffer=guess;
%tmp=color_set(count);
guess(i)=color_set(count);
if (numCallsMade==guessLimit)
finalAnswer=guess;
return
end;
[black, white, numCallsMade]=scoreme(guess,puzzleID);
if black==black_pre
if white<white_pre
index(count)=logical(0);
end;
white_pre=white;
elseif black<black_pre
guess=guess_buffer;
break;
else
black_pre=black;
white_pre=white;
break;
end;
end;
color_set=color_set(index);
end;
finalAnswer=guess;
|