permutation

How does Shingleprinting work in practice?

I'm trying to use shingleprinting to measure document similarity. The process involves the following steps: Create a 5-shingling of the two documents D1, D2 Hash each shingle with a 64-bit hash Pick a random permutation of the numbers from 0 to 2^64-1 and apply to shingle hashes For each document find the smallest of the resulting valu...

Java, lottery calculuator

Ok so i am really bored and have decided to make a lottery calculator type thing (yes i know, i am sad!) Anyway, i was wondering if there was a java library method/class for working out permutations/combinations. I want to generate all possible number sets, that have 6 numbers from 1 - 49 with no repeats in them If this isnt available...

Objective C - Permutations Calculation of Duplicates...

I can't seem to really think of a way to solve this one, can't get my brain around it for some reason. The problem I'm trying to solve is this: For a puzzle-solver type algorithm, I'm pulling the duplicate letters as a substring of an NSString. Let's say the user enters "RBEEEIOOUUU" I'm pulling just the duplicates from their string, ...

Getting all possible permutations from a list of numbers

I'm looking for an efficient way to achieve this: you have a list of numbers 1.....n (typically: 1..5 or 1..7 or so - reasonably small, but can vary from case to case) you need all combinations of all lengths for those numbers, e.g. all combinations of just one number ({1}, {2}, .... {n}), then all combinations of two distinct numbers ...

Permutation/Algorithm to Solve Conditional Fill Puzzle

I've been digging around to see if something similar has been done previously, but have not seen anything with the mirrored conditions. To make swallowing the problem a little easier to understand, I'm going to apply it in the context of filling a baseball team roster. The given roster structure is organized as such: C, 1B, 2B, 3B, SS...

Java permutation algorithm

Given a collection of integers, what's a Java algorithm that will give combinations as follows.. Given the example collection: [1,3,5], we'd want the output: [1-1] [3-3] [5-5] [1-3] [1-5] [3-5] Note that ordering is not important, so we want one of [1-3], [3-1] but not both. This should work with a collection of n numbers, not jus...

Python permutation generator puzzle

I am writing a permutation function that generate all permutations of a list in Python. My question is why this works: def permute(inputData, outputSoFar): for elem in inputData: if elem not in outputSoFar: outputSoFar.append(elem) if len(outputSoFar) == len(inputData): print outputSoF...

generate unique 5 digit number

i was told to write program which generate unique 5 digit number ( for example 12345 is unique and 11234 not) i have write following code #include <iostream> #include <stdlib.h> #include <map> using namespace std; using std::rand; const int k=99999-10234; bool unique(int t){ map<int,int>my; map<int,int>::iterator it; ...

All possible combinations of a list of a list

Hi I am in desperate need for some algorithm help when combining lists inside lists. Assuming that I have the following data structure: fields = [ ['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3'], ['d1', 'd2', 'd3'] ] I am trying to write a generator (Python) that will yield each possi...

Number of all possible groupings of a set of values?

I want to find a combinatorial formula that given a certain number of integers, I can find the number of all possible groupings of these integers (such that all values belong to a single group) Say I have 3 integers, 1, 2, 3 There would be 5 groupings: 1 2 3 1|2|3| 1 2|3 1|2 3 2|1 3 I have calculated these computationally for N = 3 t...

How does this Haskell function to calculate permutations using list comprehension work?

I'm reading Simon Thompson's Haskell: The Craft of Functional Programming, and I'm wondering how does this work: perms [] = [[]] perms xs = [ x:ps | x <- xs , ps <- perms ( xs\\[x] ) ] I can't seem to grasp how that perms( xs\\[x] ) is supposed to function. The trace of a two element list shows: perms [2,3] [ x:ps | x <- [2,3] , ps...

Algorithm for finding all permutations for n alphabets

I wrote the following algorithm for finding all possible permutations of n unique alphabets. Set<String> results = new HashSet<String>(); int size = 1; //find the total permutations possible for(int i=0;i<array.length;i++){ size*=(i+1); } // i is the number of items remaining to be shuffl...

C#: 0 & 1 Permutations

I want to list permutations with only 0 and 1. Similar to binary but allowing variable lengths, doesn't have to equal 8 length. For example: 0 1 00 01 10 11 000 001 010 011 100 101 110 111 All the way until the length of X is met. How can this be done? ...

Stopping a recursive generator & permutations

As an exercise, I've been trying out various ways of generating all permutations of a list in Python -- recursive, non-recursive... -- and comparing the performance with itertools.permutations(). But I'm having trouble with the generator version of the recursive method, which doesn't finish cleanly with a StopIteration exception, but ins...

Is there an algorithm to generate all unique circular permutations of a multiset?

I encountered this problem when doing some enthusiastic programming. The problem can be expressed as follows: For a multiset A, let P(A) denote the set of all possible permutations of A. P(A) is naturally divided into disjoint subsets that are equivalence classes, with the equivalence relation being "can be related by circ...

Enumerating a set of permutations based on a condition

I've been able to solve the following problem using std::next_permutation (c++) etc, but I'm now thinking about it in a more general and would very much like to form an expression as this type of problem seems to lend itself - though I'm not having any luck as of yet. Here is the question: Given a running race with N contestants, wha...

Arbitrary number of nested-loops?

I'm looking to take an arbitrary number of lists (e.g. [2, 1, 4 . . .], [8, 3, ...], . . .) and pick numbers from each list in order to generate all permutations. E.g.: [2, 8, ...], [2, 3, ...], [1, 8, ...], [1, 3, ...], [4, 8, ...], [4, 3, ...], ... This is easily accomplished using nested for-loops, but since I'd like to it accept...

random generate character in a string

Hi Folks i need to generate random character in a String java when user click on button. for example :if we take cat example i need to disply character in a string like follwing: CAT,ACT,TAC,TCA Thanks in advance Aswan ...

SQL: The most elegant way to generate permutations in SQL server

Given a the following table: Index | Element --------------- 1 | A 2 | B 3 | C 4 | D We want to generate all the possible permutations (without repetitions) using the elements. the final result (skipping some rows) will look like this: Results ---------- ABCD ABDC ACBD ACDB ADAC ADCA ...

permuting the rows and columns of a matrix for clustering

i have a distance matrix that is 1000x1000 in dimension and symmetric with 0s along the diagonal. i want to form groupings of distances (clusters) by simultaneously reordering the rows and columns of the matrix. this is like reordering a matrix before you visualize its clusters with a heatmap. i feel like this should be an easy proble...