General Question

BonusQuestion's avatar

Looking for a simple way to generate some permutation-like numbers!

Asked by BonusQuestion (1483points) September 24th, 2010

Given a few set of positive integers, I am trying to generate some numbers using some sort of programming .

Lets say we have three sets of integers of the same size. I would like to pick a permutation f on the first set and form a number by putting the values of f at i next to each other. Then apply the same permutation to the next set and then the last set and finally get an integer by putting these 3 numbers one after another.

For example lets say we have three sets of integers of size three, say {1, 2, 3}, {4,5,6} and {7,8,9} I would like to generate the following numbers:

123456789 (corresponding to the permutation that fixes all numbers)

132465798 (corresponding to the permutation that fixes 1 and switche 2 and 3)

321654987 (corresponding to the permutation that fixes 2 and switches 1 and 3)

213546879 (corresponding to the permutation that fixes 3 and switches 1 and 2)

231564897 (corresponding to the permutation that sends 1 to 2, 2 to 3 and 3 to 1)

312645978 (corresponding to the permutation that sends 1 to 3, 3 to 2 and 2 to 1)

How can I go about generating such numbers either online or with an accessible program?

Observing members: 0 Composing members: 0

15 Answers

Arp's avatar

If you can take the time to learn it, Pure Data might be just what you are looking for. It is pretty good at managing number sequences and creating output, which appears to be what you are looking for…

Good luck! :)

timtrueman's avatar

I would check out what Wolfram Alpha can do with combinatorics. Anything beyond what it can do and I would strong recommend giving Python a shot. Here’s something to get you started.

ratboy's avatar

This claims to work for sets up to size 7: Online Permutations Calculator.

BonusQuestion's avatar

@Arp Thank you. I will look into that.
@timtrueman Thanks but I don’t think Mathematica could help. I am pretty familiar with Wolfram softwares.
@ratboy Thank you but that’s not what I am looking for.

LostInParadise's avatar

There is an algorithm for generating permutations where each new permutation is generated by exchanging two adjacent elements of the previous one. I would think this would be helpful for you. If you returned the index values (or single value since they are adjacent) you could use this to generate the next permutation for each of your individual cases. You could probably find a description of the algorithm in a book on combinatorial algorithms, which is how I learned about it.

If you are interested, I could send you a description of the algorithm and C# code for it.

finkelitis's avatar

@BonusQuestion It seems like the simplest way would be to create a matrix where each row corresponded to an individual set of integers. Then you could permute the columns and read the numbers off. Or is that not comprehensive enough for what you’re trying to do?

camertron's avatar

Hurrah for computer science! I just whipped up a PHP class that is capable of generating all the numbers you described. If you’re interested in the source code, check it out here. It doesn’t use matrices @finkelitis although that’s a great idea. It’s basically an adaptation of the Exeter University algorithm I found here. It works by recursively switching items in the array, starting from position 0 and going to n. I set up three arrays, each containing one of the sets of three numbers you mentioned above, permuted each one, then joined them together to produce the final product. I can make this into a hosted XML web service or just a web page if you’d like so you can use it without having to host it somewhere on your own.

LostInParadise's avatar

Okay, as long as we are presenting code, this is my C# version of a fairly simple in-place permutation generator. Permutation generator It does not use recursion, but I did use the convenient yield return statement of C#. In place of the yield return you can call a program that uses the permutations. There are two axillary arrays, one that is the inverse of the permutation array and one that gives direction of movement.

The main loop has about 15 instructions. At the end of the permutation array, I give the values of the two columns that were exchanged. These two columns can be applied to any number of other permutations. I hope the documentation explains what is going on. Let me know if there are any questions.

BonusQuestion's avatar

Thanks for the suggestions.
@camertron and @LostInParadise, how do I go about running those codes. Sorry to be so illiterate but I don’t have any idea how to run those codes. :(

camertron's avatar

You can run my code by placing it on a webserver that has PHP installed, and you can run @LostInParadise‘s code by downloading Microsoft’s Visual Studio. That’s all pretty complicated though. What do you want this code to do? What’s your end goal?

I made the code runnable with some input boxes here. Hope that helps!

BonusQuestion's avatar

@camertron Thanks for taking the time to help me. I’d appreciate it.

My end goal is to check if the final numbers are divisible by a given number, and I do want the number of sets to vary.

camertron's avatar

Alright, well, what’s the largest number of sets you’d want to compute this on? It would probably be unwise to go beyond 10.

BonusQuestion's avatar

I don’t think it gets beyond 10. I think 7 would be enough for now. Thanks again.

camertron's avatar

Sure, I’ll see what I can do. It might have to wait until the weekend though :)

BonusQuestion's avatar

Thanks @camertron. A friend wrote me a code. I guess I am done with this for now. Thanks all.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther