permutation

All possible combinations of card/poker hands for a set of players

北城以北 提交于 2019-12-23 22:39:13
问题 I am looking for an elegant(fast) python function that produces every combination from the following two arrays. cards = ["8H", "8S", "8C", "8D", "9H", "9S", "9C", "9D", "10H", "10S", "10C", "10D", "AH", "AS", "AC", "AD"] players = ["_1", "_1", "_1", "_2", "_2", "_2", "_3", "_3", "_3", "_4", "_4", "_4", "_To", "_To", "_To", "_Tc"] A combination would look like: [('8H', '_1'), ('8S', '_1'), ('8C', '_1'), ('8D', '_2'), ('9H', '_2'), ('9S', '_2'), ('9C', '_3'), ('9D', '_3'), ('10H', '_3'), ('10S

Generating Fixtures from a list of n

浪子不回头ぞ 提交于 2019-12-23 21:55:25
问题 Suppose I have N teams and what to generate a fixture list, where every team plays every other team, what is the best practice for this. Is there a known algorithm that does this nicely? Efficiency isn't really a necessity as this only needs to be generated once a season. To be more specific, I'll start with some definitions: I have N teams... T_1, T_2, ... , T_n. If N is odd, include a 'ghost' team to make the amount of teams even. A set of fixtures for a week is a set of N/2 pairs, with no

Unique permutation generator?

。_饼干妹妹 提交于 2019-12-23 19:10:21
问题 The problem: I have some list of numbers, like [1,1,2] . I need to generate the unique permutations. The permutations are [1,1,2],[1,1,2],[1,2,1],[1,2,1],[2,1,1],[2,1,1] . I need to only generate the unique permutations, i.e., [1,1,2],[1,2,1],[2,1,1] . My attempt: My first attempt was to keep a set of existing permutations, and create a filter for the itertools.permutations generator that would use the set to filter out duplicates. However, for efficiency reasons, I would rather not generate

Java/ Efficient way to find all permutation of lists [duplicate]

点点圈 提交于 2019-12-23 18:21:06
问题 This question already has answers here : Cartesian product of arbitrary sets in Java (10 answers) Generating all possible permutations of a list recursively (4 answers) Closed 6 years ago . I have a list of lists in JAVA: {{1,2},{3,4,5},{6,7,8}} I try to find all permutations of this list. Meaning, In the result I would get a list with the next: {{1,3,6},{1,3,7},{1,3,8},{1,4,6}....{2,5,8}} There is a reasonable way to do it? 回答1: Here is List<List<Integer> implementation. static public void

word combination in an array using javascript

半腔热情 提交于 2019-12-23 17:37:55
问题 Let's says I've an array['Alex', 'Sam', 'Robert'] I'd like to combine them something like: Take first array[0] and append with array[2] which will be AlexRobert first letter of array[0] which is A and append with array[2] that is Robert which will be ARobert Take array[0] which is Alex and append with first letter of array[2] that is R which will be AlexR Take first array[0] append with first letter of array[1] along with array[2] which will become AlexSRobert. Basically the whole idea is

How can I use domain knowledge to improve this algorithm? Ugh, the weights

风流意气都作罢 提交于 2019-12-23 17:14:40
问题 I am having balancing trouble. I feel like I'm missing something here.. This problem equates to the following situation: On a table are a scattering of weights of various mass. In your hand are a few weights of various mass. If there is a combination of weights on the table that have a mass matching one in your hand, you can take those weights from the table, because they weigh the same as the single weight in your hand. You can drop the whole thing, including the weight from your hand, into

Algorithm to generate permutations of a list of strings and their substrings

落花浮王杯 提交于 2019-12-23 16:09:37
问题 This algorithm has been escaping me for some time now. Lets say I'm given the string "cccaatt". I'm trying to generate all the possible variations of each substring of repeated letters. EG, "cccaatt" as an input would return: cat, catt, caat, caatt, ccat, ccatt, ccaat, ccaatt, cccat, cccatt, cccaat, cccaatt The order of the results does not matter, so long as it returns all of them. Generally, the input is a string, consisting of g groups of repeated letters, each group k_n letters long. My

Count All Permutations Where No Two Adjacent Characters Are the Same

懵懂的女人 提交于 2019-12-23 15:06:34
问题 Given a sequence which contains only various amounts of the numbers 1, 2, 3, and 4 (examples: 13244, 4442, etc), I want to count all its permutations such that no two adjacent numbers are the same. I believe it is O(N! * N) and want to know if there is a better one out there. Anyone have any ideas? class Ideone { static int permutationCount++; public static void main(String[] args) { String str = "442213"; permutation("", str); System.out.println(permutationCount); } private static void

Python: Given a set of N elements, choose k at random, m times

给你一囗甜甜゛ 提交于 2019-12-23 13:07:53
问题 Given a set of N elements, I want to choose m random, non-repeating subsets of k elements. If I was looking to generate all the N choose k combinations, I could have used itertools.combination, so one way to do what I m asking would be: import numpy as np import itertools n=10 A = np.arange(n) k=4 m=5 result = np.random.permutation([x for x in itertools.permutations(A,k)])[:m] print(result) The problem is of course that this code first generates all the possible permutations, and that this

Inverting permutations in Python

蓝咒 提交于 2019-12-23 12:09:30
问题 I'm new to programming, and I'm trying to write a Python function to find the inverse of a permutation on {1,2,3,...,n} using the following code: def inv(str): result = [] i = list(str).index(min(list(str))) while min(list(str)) < len(list(str)) + 1: list(str)[i : i + 1] = [len(list(str)) + 1] result.append(i + 1) return result However, when I try to use the function, inv('<mypermutation>') returns [] . Am I missing something? Is Python skipping over my while loop for some syntactical reason