permutation

How can I find all of the permutations consisting of 1 element from a variable number of arrays of variable length?

I have an array U of arrays D that vary in length. I need to be able to return all permutations of array indices that would select a different permutation consisting of 1 element from each set. I also require that this alorithm gets represented as an object that only remembers the last permutation, and returns the next permutation with a...

Looking for "Domino combination" algorithm

Hello, I'm going to complete my apprenticeship as coder and i got a nice j2me project to work on. But i have to admit that i'm not that good with mathematical algorithms as i'd like to be. My problem is to create all possible "domino pairs" from a given set of values. For example: The possible values go from 0 to 6. Now imagine some ...

permutations in c++

I have an Array with some values e.g A=[a,b,c]; What would be the easiest/fastest way in c++ to calculate the following: int SUM; SUM= a*b + a*c + b*a + b*c + c*a + c*b; In this case a*c != c*a In the real case i have differently sized big arrays and will take the values for a,b & c from other arrays. /thanks in Advance ...

Gettting all permutations of a word or number

Using LINQ or the old-fashioned approach, how can I get all permutations of a word/number (without using an external API)? Eg ab = ab, ba, abc = acb, bac, etc Is this a specific computer science problem like image recognition, etc? Thanks ...

Comparing list of strings with an available dictionary/thesaurus

Hi all I have a program (C#) that generates a list of strings (permutations of an original string). Most of the strings are random grouping of the original letters as expected (ie etam,aemt, team). I wanna find the one string in the list that is an actual English word, programatically. I need a thesaurus/dictionary to look up and comp...

Combining words in Python (permutations?)

Suppose I have 4 words, as a string. How do I join them all like this? s = orange apple grapes pear The result would be a String: "orangeapple/orangegrapes/orangepear/applegrapes/applepear/grapespear/orangeapplegrapes/orangeapplepear/applegrapespear" I am thinking: list_words = s.split(' ') for l in list_words: And then use enum...

How to find permutation of k in a given length?

How can I find the permutations of for example 2 in a size of 3. For example: The word cat has 3 letters: How can I find all the permutations of 2 in the word cat. Result should be: ac, at, ca, ac, etc... This is not a homework problem. Any language could be used but more preferable: C/C++ or C#. I know how to create the recursion ...

Generate all combinations of arbitrary alphabet up to arbitrary length

Say I have an array of arbitrary size holding single characters. I want to compute all possible combinations of those characters up to an arbitrary length. So lets say my array is [1, 2, 3]. The user-specified length is 2. Then the possible combinations are [11, 22, 33, 12, 13, 23, 21, 31, 32]. I'm having real trouble finding a suitabl...

How would you calculate all possible permutations of 0 through N iteratively?

I need to calculate permutations iteratively. The method signature looks like: int[][] permute(int n) For n = 3 for example, the return value would be: [[0,1,2], [0,2,1], [1,0,2], [1,2,0], [2,0,1], [2,1,0]] How would you go about doing this iteratively in the most efficient way possible? I can do this recursively, but I'm int...

How should I go about generating every possible map<char, char> combination from map<char, vector<char> > ?

I am looking to take a map<char, vector<char> > and generate each possible map<char, char> from it. I understand this may use a sizeable amount of memory and take a bit of time. Each map<char, char> needs to contain every letter a-z, and be mapped to a unique a-z character. ie. ak bj cp dy ev fh ga hb ir jq kn li mx nc oo pz qs rl sd t...

Algorithm to generate all possible letter combinations of given string down to 2 letters

Algorithm to generate all possible letter combinations of given string down to 2 letters Trying to create an Anagram solver in AS3, such as this one found here: http://homepage.ntlworld.com/adam.bozon/anagramsolver.htm I'm having a problem wrapping my brain around generating all possible letter combinations for the various lengths of ...

What are the Ruby equivalent of Python itertools, esp. combinations/permutations/groupby?

Python's itertools module provides a lots of goodies with respect to processing an iterable/iterator by use of generators. For example, permutations(range(3)) --> 012 021 102 120 201 210 combinations('ABCD', 2) --> AB AC AD BC BD CD [list(g) for k, g in groupby('AAAABBBCCD')] --> AAAA BBB CC D What are the equivalent in Ruby? By eq...

Calculating the maximum distance between elements of vector in MATLAB

Let's assume that we have a vector like x = -1:0.05:1; ids = randperm(length(x)); x = x(ids(1:20)); I would like to calculate the maximum distance between the elements of x in some idiomatic way. It would be easy to just iterate over all possible combinations of x's elements but I feel like there could be a way to do it with MATLAB's ...

How to calculate the cycles that change one permutation into another?

Hi, I'm looking for an algorithm that given two permutations of a sequence (e.g. [2, 3, 1, 4] and [4, 1, 3, 2]) calculates the cycles that are needed to convert the first into the second (for the example, [[0, 3], [1, 2]]). The link from mathworld says that Mathematica's ToCycle function does that, but sadly I don't have any Mathematica...

Maths Question: number of different permutations

This is more of a maths question than programming but I figure a lot of people here are pretty good at maths! :) My question is: Given a 9 x 9 grid (81 cells) that must contain the numbers 1 to 9 each exactly 9 times, how many different grids can be produced. The order of the numbers doesn't matter, for example the first row could conta...

How much does precomputation (matching a series of strings and their permutations with a set number of other strings) help, especially over a network ?

Consider a typical slots machine with n reels(say reel1: a,b,c,d,w1,d,b, ..etc). On play we generate a concatenated string of n objects (like for above, chars) We have a paytable which lists winning strings with payout amounts. The problem is a wild character (list of wilds: w1,w2) which can replace {w1:a,b,c},{w2:a} ..etc. Is it reall...

What are some practical uses of generating all permutations of a list, such as ['a', 'b', 'c'] ?

I was asked by somebody in an interview for web front end job, to write a function that generates all permutations of a string, such as "abc" (or consider it ['a', 'b', 'c']). so the expected result from the function, when given ['a', 'b', 'c'], is abc acb bac bca cab cba Actually in my past 20 years of career, I have never needed to...

algorithm for python itertools.permutations

Can someone please explain algorithm for itertools.permutations routine in Python standard lib 2.6? I see its code in the documentation but don't undestand why it work? Thanks Code is: def permutations(iterable, r=None): # permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC # permutations(range(3)) --> 012 021 10...

Algorithm to generate 1000 distinct integers in the range [0,8000]?

What are some alternative methods to generate 1000 distinct random integers in the range [0,8000] as opposed to the following: naive method: generating a number and checking if it's already in the array. O(n^2) linear shuffle: generate sequence 0 to 8000, shuffle, take the first 1000. O(n) ...

A Combinations of Items in Given List

Hello stackoverflow, I'm currently in Python land. This is what I need to do. I have already looked into the itertools library but it seems to only do permutations. I want to take an input list, like ['yahoo', 'wikipedia', 'freebase'] and generate every unique combination of one item with zero or more other items... ['yahoo', 'wikipe...