• Main Page
  • Files
  • File List
  • File Members

/Users/garethloy/Musimathics/Musimat1.2/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         /*****************************************************************************
00041          prints 10, 11, 12, 11, 12, 10, 12, 10, 11. Because inc = -1, it skips back one place in the 
00042          row every time. The trigger for it to skip is when it has output as many elements as are in the list.
00043          *****************************************************************************/
00044 }
00045 
00047 /* $Revision: 1.3 $ $Date: 2006/09/05 08:02:45 $ $Author: dgl $ $Name:  $ $Id: C091201c.cpp,v 1.3 2006/09/05 08:02:45 dgl Exp $ */
00048 // The Musimat Tutorial © 2006 Gareth Loy
00049 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy 
00050 // and published exclusively by The MIT Press.
00051 // This program is released WITHOUT ANY WARRANTY; without even the implied 
00052 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
00053 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
00054 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
00055 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
00056 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
00057 // The Musimat website:                 http://www.musimat.com/
00058 // This program is released under the terms of the GNU General Public License
00059 // available here:                      http://www.gnu.org/licenses/gpl.txt
00060 

Generated on Fri Nov 26 2010 16:18:24 for Musimat Chapter 9 Code Examples by  doxygen 1.7.2