permutation

Generating Random Permutation Uniformly in Java

假如想象 提交于 2020-01-01 19:20:36
问题 Anyone know of a fast/the fastest way to generate a random permutation of a list of integers in Java. For example if I want a random permutation of length five an answer would be 1 5 4 2 3 , where each of the 5! possibilities is equally likely. My thoughts on how to tackle this are to run a method which generates random real numbers in an array of desired length and then sorts them returning the index i.e. 0.712 0.314 0.42 0.69 0.1 would return a permutation of 5 2 3 4 1 . I think this is

itertools: Cartesian product of permutations

ⅰ亾dé卋堺 提交于 2020-01-01 15:36:09
问题 Using pythons itertools , I'd like to create an iterator over the outer product of all permutations of a bunch of lists. An explicit example: import itertools A = [1,2,3] B = [4,5] C = [6,7] for x in itertools.product(itertools.permutations(A),itertools.permutations(B),itertools.permutations(C)): print x While this works, I'd like to generalize it to an arbitrary list of lists. I tried: for x in itertools.product(map(itertools.permutations,[A,B,C])): print x but it did not do what I intended.

itertools: Cartesian product of permutations

限于喜欢 提交于 2020-01-01 15:36:04
问题 Using pythons itertools , I'd like to create an iterator over the outer product of all permutations of a bunch of lists. An explicit example: import itertools A = [1,2,3] B = [4,5] C = [6,7] for x in itertools.product(itertools.permutations(A),itertools.permutations(B),itertools.permutations(C)): print x While this works, I'd like to generalize it to an arbitrary list of lists. I tried: for x in itertools.product(map(itertools.permutations,[A,B,C])): print x but it did not do what I intended.

How can I generate a “Social Golfer” matrix for worker seating arrangement?

不羁岁月 提交于 2020-01-01 04:51:06
问题 This challenge is a Social Golfer Problem scenario. I have a company with 320 persons. I recently implemented a Management By Objectives (MBO) program where each worker is assigned goals to be completed on a monthly basis. One of the recurring goals is to arrive on time at work to attend a 30 minute coffee and dounut meeting each morning. The meeting is held in our dinning hall which has 50 tables. Each table can seat up to 8 persons maximum. Plus or minus 80 seats are empty each workday, as

How to generate a permutation?

一世执手 提交于 2019-12-31 10:49:51
问题 My question is: given a list L of length n, and an integer i such that 0 <= i < n!, how can you write a function perm(L, n) to produce the ith permutation of L in O(n) time? What I mean by ith permutation is just the ith permutation in some implementation defined ordering that must have the properties: For any i and any 2 lists A and B, perm(A, i) and perm(B, i) must both map the jth element of A and B to an element in the same position for both A and B. For any inputs (A, i), (A, j) perm(A,

how to produce every permutation of positioning 20 values of -1 in a 1-by-41 vector of ones?

牧云@^-^@ 提交于 2019-12-31 04:50:11
问题 I have written different code to produce different permutations of ones and minus ones. they work for matrixes with small dimensions: for example: S=[-1 -1 1 1 1 1 1 1]; P=unique(perms(S),'rows'); produces: -1 -1 1 1 1 1 1 1 -1 1 -1 1 1 1 1 1 -1 1 1 -1 1 1 1 1 -1 1 1 1 -1 1 1 1 -1 1 1 1 1 -1 1 1 -1 1 1 1 1 1 -1 1 -1 1 1 1 1 1 1 -1 1 -1 -1 1 1 1 1 1 1 -1 1 -1 1 1 1 1 1 -1 1 1 -1 1 1 1 1 -1 1 1 1 -1 1 1 1 -1 1 1 1 1 -1 1 1 -1 1 1 1 1 1 -1 1 1 -1 -1 1 1 1 1 1 1 -1 1 -1 1 1 1 1 1 -1 1 1 -1 1 1 1

Determine if A is permutation of B using ASCII values

南楼画角 提交于 2019-12-31 03:11:53
问题 I wrote an function to determine if string a is a permutation of string b . The definition is as follows: bool isPermutation(std::string a, std::string b){ if(a.length() != b.length()) return false; int a_sum, b_sum; a_sum = b_sum = 0; for(int i = 0; i < a.length(); ++i){ a_sum += a.at(i); b_sum += b.at(i); } return a_sum == b_sum; } The issue with my approach is that if a = 600000 and b = 111111 , the function returns true. Is there any way I can keep my general approach to this problem (as

Determine if A is permutation of B using ASCII values

拟墨画扇 提交于 2019-12-31 03:11:34
问题 I wrote an function to determine if string a is a permutation of string b . The definition is as follows: bool isPermutation(std::string a, std::string b){ if(a.length() != b.length()) return false; int a_sum, b_sum; a_sum = b_sum = 0; for(int i = 0; i < a.length(); ++i){ a_sum += a.at(i); b_sum += b.at(i); } return a_sum == b_sum; } The issue with my approach is that if a = 600000 and b = 111111 , the function returns true. Is there any way I can keep my general approach to this problem (as

How can I generate a list of all possible permutations of several letters? [duplicate]

瘦欲@ 提交于 2019-12-31 01:50:11
问题 This question already has answers here : How to generate all permutations of a list? (30 answers) Randomize a string input into all possibilities (1 answer) Closed 5 years ago . So I am making a word generator that takes several inputted letters, puts them in all possible positions, and matches them with a document to find words. If I am approaching this wrong please tell me! If not how can I do this? Thanks 回答1: to generate all permutations of a given list of letters, use the itertools

Python Itertools permutations only letters and numbers

南楼画角 提交于 2019-12-30 10:16:41
问题 I need to get only the permutations that have letters and numbers (The permutation can not be. "A, B, C, D" I need it like this: "A, B, C, 1") In short, the permutations can not contain only letters, not just numbers. Must be a combination of both. My code: import itertools print list(itertools.combinations([0,1,2,3,4,'a','b','c','d'], 4)) Then I get: [(0, 1, 2, 3), (0, 1, 2, 4), (0, 1, 2, 'a'), (0, 1, 2, 'b'), (0, 1, 2, 'c'), (0, 1, 2, 'd'), (0, 1, 3, 4), (0, 1, 3, 'a'), (0, 1, 3, 'b'), (0,