- Main Page
- Namespaces
- Files

- File List
- File Members

# C:/Musimathics_local/Musimat/MusimatChapter9/C091201c.cpp

Go to the documentation of this file.

    00001 #include "MusimatChapter9.h"
    00002 MusimatChapter9Section(C091201c) {
    00003 Print("*** Permutation ***");
    00004 /*****************************************************************************
    00005
    00006 Permutation
    00007
    00008 Iterate the supplied sequence in prime order until exhausted, then permute the
    00009 entire row by inc steps and repeat from the beginning.
    00010 *****************************************************************************/
    00011         para1(); // Step into this function to continue.
    00012 }
    00013
    00014 Integer permute(IntegerList L, Integer Reference pos,
    00015         Integer Reference count, Integer inc) {
    00016         Integer curPos = pos;                                                   // save current position
    00017         Integer x = cycle(L, pos, 1);                                   // update pos and get list value
    00018         count = count + 1;                                                              // increment counter
    00019         If (count == Length(L)){                                                // have we output L items from list?
    00020                 count = 0;                                                                      // reset count
    00021                 pos = curPos + inc;                                                     // permute position for next time
    00022         }
    00023         Return(x);
    00024 }
    00025
    00026 Static Void para1() {
    00027 /*****************************************************************************
    00028 Here is an example of invoking permute().
    00029 *****************************************************************************/
    00030         Print("*** Permutation ***");
    00031         IntegerList L(10, 11, 12);
    00032         Integer inc = -1;
    00033         Integer pos = 0;
    00034         Integer perm = 0;
    00035
    00036         For (Integer i = 0; i < 3 * Length(L); i++)
    00037                         Print(permute(L, pos, perm, inc));
    00038
    00039 /*****************************************************************************
    00040 prints 10, 11, 12, 11, 12, 10, 12, 10, 11. Because inc = –1, it skips back one place in the
    00041 row every time. The trigger for it to skip is when it has output as many elements as are in the list.
    00042 *****************************************************************************/
    00043 }}
    00044
    00046 /* $Revision: 1.2 $ $Date: 2006/09/09 06:22:42 $ $Author: dgl $ $Name:  $ $Id: _c091201c_8cpp-source.html,v 1.2 2006/09/09 06:22:42 dgl Exp $ */
    00047 // The Musimat Tutorial © 2006 Gareth Loy
    00048 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy
    00049 // and published exclusively by The MIT Press.
    00050 // This program is released WITHOUT ANY WARRANTY; without even the implied
    00051 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00052 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
    00053 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
    00054 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
    00055 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
    00056 // The Musimat website:                 http://www.musimat.com/
    00057 // This program is released under the terms of the GNU General Public License
    00058 // available here:                      http://www.gnu.org/licenses/gpl.txt
    00059