|
Calling Sequence
|
|
MixedRadixTuples(radices, opts)
|
|
Parameters
|
|
radices
|
-
|
list(nonnegint)
|
opts
|
-
|
(optional) equation(s) of the form option = value; specify options for the MixedRadixTuples command
|
|
|
|
|
Options
|
|
|
True means compile the iterator. The default is true.
|
|
Specify the starting rank of the iterator. The default is one. Passing a value greater than one causes the iterator to skip the lower ranks; this can be useful when parallelizing iterators. The starting rank reverts to one when the iterator is reset, reused, or copied.
|
|
|
Description
|
|
•
|
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.
|
|
Methods
|
|
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.
|
|
|
|
Examples
|
|
Construct an iterator that generates the tuples with the radices .
>
|
|
| (1) |
Compute the number of iterations.
Return the element with rank equal to 4.
Copy the iterator, but start with rank equal to 4.
>
|
|
| (4) |
|
Making Change
|
|
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)
local i;
sprintf("%d pennies + %d nickels "
"+ %d dimes + %d quarters "
"= 75 cents"
, seq(i, i=V));
end proc:
|
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
| |
|
|
|
References
|
|
|
Knuth, Donald Ervin. The Art of Computer Programming, volume 4, fascicle 2; generating all tuples and permutations, p. 2, sec. 7.2.1.1, generating all n-tuples, algorithm M, mixed-radix generation.
|
|
|
Compatibility
|
|
•
|
The Iterator[MixedRadixTuples] command was introduced in Maple 2016.
|
•
|
The Iterator[MixedRadixTuples] command was updated in Maple 2022.
|
•
|
The radices parameter was updated in Maple 2022.
|
|
|
|