
% Initialize variables
MIN = 1;
MAX = 3;
MAXBOXES = 7;

boxesToAdd = floor(rand*(MAX-MIN+1)+MIN);
boxesInBin = 0;
boxesTaken= 0;
totalBoxes = 0;
eff = 1.0;
count = 0;

while (boxesInBin + boxesToAdd) <= MAXBOXES
   count = count + 1;
   boxesInBin = boxesInBin + boxesToAdd;

   boxesTaken = floor (eff*rand*(MAX-MIN +1) + MIN);
   if boxesTaken <= boxesInBin
	totalBoxes = boxesTaken + totalBoxes;
        boxesInBin = boxesInBin - boxesTaken;
   else
	totalBoxes = boxesInBin + totalBoxes;
        boxesInBin = 0;
   end
   if mod ( count, 4) == 0
	eff = .75;
   end

   boxesTaken = floor (eff * (rand*(MAX-MIN+1) + MIN);
end

disp ( ['Total boxes taken:', num2str(totalBoxes)]  )
disp ( strcat ('Number of cycle is: ', num2str(count) ))
