permutation

How to check if permutations have equal parity?

I am looking for a way to check if 2 permutations (represented by lists) are of the same parity. Note that I am not interested if they are even or odd parity, just the equality. I am new to Python and my naive solution is given below as a reply. I am looking forward to Python gurus showing me some cool tricks to achieve the same in less...

Fast permutation -> number -> permutation mapping algorithms

I have n elements. For the sake of an example, let's say, 7 elements, 1234567. I know there are 7! = 5040 permutations possible of these 7 elements. I want a fast algorithm comprising two functions: f(number) maps a number between 0 and 5039 to a unique permutation, and f'(permutation) maps the permutation back to the number that it...

OCaml: Permutation of every value in two sets? (how to translate this from Java)

I have two sets, returned by Set.Make(t). I would like to generate every possible combination of the values in the two. How can I do this? This works to generate some pairs, but not all: List.combine (IntSet.elements odp) (IntSet.elements ftw) This would do it in Java: for (int i : ktr) { for (int m : mnx) { System.out.p...

Generate all Permutations of text from a regex pattern in C#

So i have a regex pattern, and I want to generate all the text permutations that would be allowed from that pattern. Example: var pattern = "^My (?:biological|real)? Name is Steve$"; var permutations = getStringPermutations(pattern); This would return the list of strings below: My Name is Steve My real Name is Steve My biological ...

Good hash function for permutations?

I have got numbers in a specific range (usually from 0 to about 1000). An algorithm selects some numbers from this range (about 3 to 10 numbers). This selection is done quite often, and I need to check if a permutation of the chosen numbers has already been selected. e.g one step selects [1, 10, 3, 18] and another one [10, 18, 3, 1] the...

Enumerating Permutations of a set of subsets

I have sets S1 = {s11,s12,s13), S2 = {s21,s22,s23) and so on till SN.I need to generate all the permutations consisting elements of S1,S2..SN.. such that there is only 1 element from each of the sets. For eg: S1 = {a,b,c} S2 = {d,e,f} S3 = {g,h,i} My permuations would be: {a,d,g}, {a,d,h}, {a,d,i}, {a,e,g}, {a,e,h}.... How would ...

Worker/Timeslot permutation/constraint filtering algorithm

Hope you can help me out with this guys. It's not help with work -- it's for a charity of very hard working volunteers, who could really use a less confusing/annoying timetable system than what they currently have. If anyone knows of a good third-party app which (certainly) automate this, that would almost as good. Just... please don'...

How can I maximally partition a set?

I'm trying to solve one of the Project Euler problems. As a consequence, I need an algorithm that will help me find all possible partitions of a set, in any order. For instance, given the set 2 3 3 5: 2 | 3 3 5 2 | 3 | 3 5 2 | 3 3 | 5 2 | 3 | 3 | 5 2 5 | 3 3 and so on. Pretty much every possible combination of the members of the set....

Code to generate Permutations for a given set of numbers efficiently C#

Can anyone please write or give me a link where I can find the C# code to list all the permutations for a give set of numbers in the most efficient manner? ...

Permutations of a given set of numbers

Can someone please explain a good algorithm to find all permutations of a given set of numbers in an efficient manner? ...

Algorithm for generating huge wordlist

Alright, I know this is going to sound bad, like I'm going to use this for un-ethical things, but you have my word that I am not. I am writing a paper for my Computer and Information Security course and the topic I chose was hashing methods. One of the points that I go over in my paper is MD5 being only one-way and the only way to crack...

How do I get all permutations of xPy in C?

I'd like to calculate all the permutations of size Y of a set of size X. That is if I had (1,2,3) and want all permutations of size 2, 3P2, it would be (1,2) (1,3) (2,1) (2,3) (3,1) (3,2). Both the GSL and C++ STL only provide xPx that I can see. Could someone point me at a C/C++ library which can do this or spell out a fast and memor...

Java: Generate a Powerset

This could be language agnostic/helpful answers could just be in pseudo-code. I have a program that I would like to test under a range of inputs. This program takes a set of files, one of which is designated as the root. I want to run the program with all possible subsets of files. (Two subsets, containing the same files, but with diffe...

Recursion and permutations

Hi. Let's say that we have two boxes of pencils (in first box just blue and in second just red pencils). So the question now is, in how many ways can we put x red and y blue pencils in the line? Example: we have 3 Red pencils, and 1 Blue. Then we have 4 different ways. Combinations: BRRR, RBRR, RRBR, RRRB. So with 10 Red and 10 Blue ...

Generating non-duplicate permutation pairs in R

Sorry for the non-descriptive title but I don't know whether there's a word for what I'm trying to achieve. Let's assume that I have a list of names of different classes like c( '1', '2', '3', '4') I'd like to generate all possible permutation pairs out of this so that there are no reverse-duplicates. So what I'd like to have is some...

Generating n-digit numbers sequenced by sum of individual digits (without recursion)

I'm looking to generate all possible values of n-digit number, in the following order, where the sequence is dictated by the sum of the individual digits. For example, with n = 3: 111 sum = 3 112 sum = 4 121 211 122 sum = 5 212 221 113 131 311 114 sum = 6 141 411 ::: 999 sum = 27 The order within the sum group is ...

Best algorithm to find all possible permutation of given binary bits

Hi, I am looking for an optimal algorithm to find out remaining all possible permutation of a give binary number. For ex: Binary number is : ........1. algorithm should return the remaining 2^7 remaining binary numbers, like 00000001,00000011, etc. Thanks, sathish ...

fixed-length permutations of a string

I'm trying to take a seven-character string and generate all the possible 3- and 4-letter permutations of it. This seems like something that recursion would be handy for (most all permutation generators I've seen are recursive), but I keep getting stuck at how to avoid repetition. That is, if my input string is "aabcdef" I don't want any...

Java permutations with least random numbers possible

hi folks! i looking to generate a permutation of the array a and I dont want to use util function such as shuffle on collections... The permutations(#) should be randomised and every single permutation should be possible - but there is no need for an equally distributed probability. the following code was the first idea that struck my mi...

Need help with brute force code for crypt(3)

Hello, I am trying to develop a program in C that will "crack" the crypt(3) encryption used by UNIX. The most naive way to do it is brute forcing I guess. I thought I should create an array containing all the symbols a password can have and then get all possible permutations of them and store them in a two-dimensional array (where all th...