%% y = next_base (x, n) - Number in base n after x 
%%
%% Return the number written in base n that is after x. 
%%
%% INPUT:
%% x : vector representing a number written in base n. 1x(1) is the 1st
%%     digit, x(2) the second etc.
%% n : base.
%%
%% OUTPUT:
%% y : vector representing the number x+1 in base n.
%%
%% Example: next_base(6,7) == [1 0];
%%
%% See also : next_set.

%% Author : Etienne Grossmann <etienne@cs.uky.edu>

function x = next_base (x,b)

n=length(x); 

while (n>0) && x(n)>=b-1 	% Find next digit that isn't b-1
  x(n--)=0; 
end;

if n, x(n)++; 			% Increment digit 
else  x = [1,x(:)']; 		% Add a leading 1
end; 
end
