Name

intprb_tuplenext — Computes the next element of a tuple space.

Calling Sequence

   [ rnk, x ] = intprb_tuplenext ( m1, m2, n, rnk, x )
   
   

Parameters

m1:

the minimum entry.

m2:

the maximum entry.

n:

the number of components.

rnk:

counts the elements. On first call, set rnk to 0. On subsequent calls, the input value of rnk should be the output value of rnk from the previous call. On output, the order of the next tuple. When there are no more elements, rnk will be returned as 0.

x:

on input, the previous tuple. On output, the next tuple.

Description

The elements are n vectors. Each entry is constrained to lie between m1 and m2. The elements are produced one at a time. The first element is (m1,m1,...,m1), the second element is (m1,m1,...,m1+1), and the last element is (m2,m2,...,m2) Intermediate elements are produced in lexicographic order.

Examples

// Displays all tuples of length 2 with elements between 1 and 3.
n = 2;
m1 = 1;
m2 = 3;
rnk = 0;
ic = [];
computed = [];
for i = 1 : 12
[ rnk, ic ] = intprb_tuplenext ( m1, m2, n, rnk, ic );
disp([rnk ic'])
end
// Notice that the vector [0 0] announces that the end has been reached.
// From there, the algorithm circles.

   

Authors

2007 - John Burkardt (MATLAB version)
2010 - Michael Baudin (Scilab version)