Math question

1. Senior Member
Join Date
Dec 1969
Posts
258

## Math question

I&#039;m not a math person so here&#039;s a puzzle for you:<BR>I need to create all the possible permutations of a set.<BR><BR>So far, I know that I have to loop the same number of times as the number of items in the set:<BR><BR>set(n)<BR><BR>for x=0 to n-1<BR><BR>Here I need to calculate all the different permutations of n things taken x at a time.<BR><BR>next<BR><BR>Anyone have any ideas of how to create all the different permutation of n things taken x at at time?

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Is this homework?

If so, I&#039;d rather you write the code.<BR><BR>I&#039;ll give you hints, though:<BR><BR>If you take N things X at a time, the fastest way to code is with X nest loops. But the coding is ugly and complex. And doesn&#039;t work if you don&#039;t know ahead of time what X is.<BR><BR>If you don&#039;t know ahead of time what X is, then recursion is the best answer.<BR><BR>The trick, in VBScript coding, is figuring out how to pass the diminished set to the next level in the recursion. That is, after level 1 chooses one of the N items, how do you pass the entire set--minus the chosen one--on to level 2? And after level 2 chooses another item, how do you pass the set minus two to the level 3? Etc.<BR><BR>Figure that out and you&#039;re home free.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
258

## RE: Is this homework?

You gave me a chuckle. I&#039;m 37.<BR><BR>It&#039;s for a hobby site I&#039;m building for a friend.

4. Senior Member
Join Date
Dec 1969
Posts
1,407

## RE: Is this homework?

magic squares can be created using recursion and permutations........check this out, maybe it will help:<BR><BR>http://personal.vsnl.com/erwin/magic.htm

5. Senior Member
Join Date
Dec 1969
Posts
258

## Thanks BW and JSW <eot>

.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•