#include "MusimatChapter9.h"Go to the source code of this file.
Functions | |
| MusimatChapter9Section (C091201c) | |
| Integer | permute (IntegerList L, Integer Reference pos, Integer Reference count, Integer inc) | 
| Static Void | para1 () | 
| MusimatChapter9Section | ( | C091201c | ) | 
Definition at line 2 of file C091201c.cpp.
References para1().
                                 {
        Print("*** Permutation ***");
        /*****************************************************************************
         
         Permutation
         
         Iterate the supplied sequence in prime order until exhausted, then permute the 
         entire row by inc steps and repeat from the beginning.
         *****************************************************************************/
        para1(); // Step into this function to continue.
}
| Static Void para1 | ( | ) | 
Definition at line 26 of file C091201c.cpp.
References permute().
                    {
        /*****************************************************************************
         Here is an example of invoking permute().
         *****************************************************************************/
        Print("*** Permutation ***");
        IntegerList L(10, 11, 12);
        Integer inc = -1;
        Integer pos = 0;
        Integer perm = 0;
        
        For (Integer i = 0; i < 3 * Length(L); i++) {
                Print(permute(L, pos, perm, inc));
        }
        
        /*****************************************************************************
         prints 10, 11, 12, 11, 12, 10, 12, 10, 11. Because inc = -1, it skips back one place in the 
         row every time. The trigger for it to skip is when it has output as many elements as are in the list.
         *****************************************************************************/
}
| Integer permute | ( | IntegerList | L, | 
| Integer Reference | pos, | ||
| Integer Reference | count, | ||
| Integer | inc | ||
| ) | 
Definition at line 14 of file C091201c.cpp.
References cycle().
                                                                      { 
        Integer curPos = pos;                                                   // save current position
        Integer x = cycle(L, pos, 1);                                   // update pos and get list value
        count = count + 1;                                                              // increment counter
        If (count == Length(L)) {                                               // have we output L items from list?
                count = 0;                                                                      // reset count
                pos = curPos + inc;                                                     // permute position for next time
        }
        Return(x); 
}
 1.7.2