Use Permute to construct an iterator over all permutations of the list [1,2,2,3].
Use a for-loop to iterate over the permutations.
1 2 2 3
1 2 3 2
1 3 2 2
2 1 2 3
2 1 3 2
2 2 1 3
2 2 3 1
2 3 1 2
2 3 2 1
3 1 2 2
3 2 1 2
3 2 2 1
| |
The same output is more conveniently generated with the Print method. Here the number of iterations is limited and showrank option is used to display the rank.
1: 1 2 2 3
2: 1 2 3 2
3: 1 3 2 2
4: 2 1 2 3
5: 2 1 3 2
6: 2 2 1 3
7: 2 2 3 1
8: 2 3 1 2
9: 2 3 2 1
10: 3 1 2 2
| |
Use a seq command to create the entire sequence.
Note the use of the square brackets, [], to instantiate the Vector that is assigned to p. Without them, all values in the final expression sequence equal the last value because the p' evaluates to the Vector rather than its content. Here is what happens when the square brackets are omitted.
|
Using hasNext and getNext
|
|
•
|
Use Combination to generate all triplets of the integers 0 to 4. Extract the two procedures, hasNext and getNext, from the ModuleIterator method of the iterator object and use them in a while-loop.
|
|
|
Concurrent iterators
|
|
Construct an iterator over the 2-permutations of the list , use Object to create an identical, but independent, second iterator, and use both iterators in a dual-loop.
|