Skip to content

Instantly share code, notes, and snippets.

@gidili
Created March 18, 2010 01:24
Show Gist options
  • Save gidili/335942 to your computer and use it in GitHub Desktop.
Save gidili/335942 to your computer and use it in GitHub Desktop.
function [C] = generateBinaryInitialConfigurations(total, sizeOfEach)
% will generate [total] initial configuration each of size [sizeOfEach]
howManyOfEach = total/2;
blackCounter = 0;
whiteCounter = 0;
tot = 0;
while((blackCounter < howManyOfEach || whiteCounter < howManyOfEach) && tot<total)
a = randint(1, sizeOfEach, [0 1]);
if(sum(a)>sizeOfEach/2 && blackCounter < howManyOfEach)
blackCounter = blackCounter +1;
C(tot+1, :) = a;
tot = tot+1;
elseif (sum(a)<sizeOfEach/2 && whiteCounter < howManyOfEach)
whiteCounter = whiteCounter +1;
C(tot+1, :) = a;
tot = tot+1;
end
end
%test output
%disp([num2str(blackCounter) ' ' num2str(whiteCounter) ' ' num2str(total) ' ' num2str(tot)])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment