generate mixed-radix tuples
(optional) equation(s) of the form option = value; specify options for the MixedRadixTuples command
compile = truefalse
True means compile the iterator. The default is true.
rank = nonnegint
Specify the starting rank of the iterator. The default is one. The starting rank reverts to one when the iterator is reset, reused, or copied.
The MixedRadixTuples command returns an iterator that generates all tuples of a mixed-radix number.
The radices parameter is a list of positive integers that specify the radices of the number. The k-th integer is the radix at the k-th index.
In addition to the common iterator methods, this iterator object has the following methods. The self parameter is the iterator object.
Number(self): return the number of iterations required to step through the iterator, assuming it started at rank one.
Rank(self,L): return the rank of the current iteration. Optionally pass L, a list or one-dimensional rtable, and return its rank.
Unrank(self,rnk): return a one-dimensional Array corresponding to the iterator output with rank rnk.
Construct an iterator that generates the tuples with the radices 2,4,3.
Compute the number of iterations.
Return the element with rank equal to 4.
Copy the iterator, but start with rank equal to 4.
Given 7 pennies (1-cent coin), 5 nickels (5-cents), 3 dimes (10-cents), and 3 quarters (25-cents), list all ways to change 75 cents.
Assign a procedure that converts a Vector of the number of coins to a string. The contents of the Vector are the number of pennies, nickels, dimes, and quarters, in that order.
Change := proc(V)
sprintf("%d pennies + %d nickels "
"+ %d dimes + %d quarters "
"= 75 cents"
, seq(i, i=V));
Assign a predicate that returns true if the Vector V has the exact change.
Iterate through all all possibilities, accepting those that are exact, and transforming the Vector to the desired string.
5 pennies + 4 nickels + 0 dimes + 2 quarters = 75 cents
5 pennies + 2 nickels + 1 dimes + 2 quarters = 75 cents
0 pennies + 3 nickels + 1 dimes + 2 quarters = 75 cents
5 pennies + 0 nickels + 2 dimes + 2 quarters = 75 cents
0 pennies + 1 nickels + 2 dimes + 2 quarters = 75 cents
Knuth, Donald Ervin. The Art of Computer Programming, volume 4, fascicle 2; generating all tuples and permutations, p. 2, sec. 18.104.22.168, generating all n-tuples, algorithm M, mixed-radix generation.
The Iterator[MixedRadixTuples] command was introduced in Maple 2016.
For more information on Maple 2016 changes, see Updates in Maple 2016.
Download Help Document
What kind of issue would you like to report? (Optional)