combinatorics

Algorithm: Selecting pairs of teams from a set of games

笑着哭i 提交于 2020-01-14 19:51:11
问题 I'm trying to create a scheduler for a sports league and I'd like to schedule the teams in groups so every team gets one game per group. I think the thing I'm trying to do is an existing problem in computer science, but I don't know what it's called and I'm having trouble finding information about it. Either way, here's the situation: Let's say I have a set of teams A = {1,2,3,...,n} and a set of pairs of those teams B = {(1,2), (1,3), (2,4), (6,9),...} . B does not have every possible

Find all possible combinations of arguments in Python

时光毁灭记忆、已成空白 提交于 2020-01-14 05:18:46
问题 I have a function that has a following signature: def function(a=None, b=None, c=None): # ... some more code ... If passed, a, b and c can only be booleans. I want to know all the valid combinations of a, b and c. Note that a, b and c are optional, so this function can be called with as little as 0 parameters and as much as 3 parameters. I'm able to get all the possible argument combinations: arg_names = ['a', 'b', 'c'] arg_values = [None, True, False] arg_combinations = [] for i in range(len

Creating Combinations of Elements

梦想与她 提交于 2020-01-14 05:12:31
问题 I want to create product option system. I have a form look like this: Form's inputs are tag inputs. First input is option name. When you put any option name the new tag input added in the form. My problem: I can't create combinations in controller because the inputs name an quantity will be random. Current Code: I found this code but i cant customize it for my system First inputs code id: when i post data goes to controller post it another blade. i incude this in my page In controller public

Determine list of all possible products from a list of integers in Python

情到浓时终转凉″ 提交于 2020-01-13 07:30:10
问题 In Python 2.7 I need a method that returns all possible products of a list or tuple of int . Ie. if input is (2, 2, 3, 4) , then I'd want a output like (3, 4, 4) , 2 * 2 = 4 (2, 4, 6) , 2 * 3 = 6 (2, 3, 8) , 2 * 4 = 8 (3, 4, 4) , 2 * 2 = 4 (2, 2, 12) , 3 * 4 = 12 (2, 24) , 2 * 3 * 4 = 24 (3, 16) , 2 * 2 * 4 = 16 (4, 12) , 2 * 2 * 3 = 12 (48) , 2 * 2 * 3 * 4 = 48 wrapped up in a list or tuple . I figure that a nice implementation is probably possible using combinations from itertools , but I'd

All permutations with repetition using scala

梦想的初衷 提交于 2020-01-12 17:31:31
问题 I am looking for the scala way to give all permutations without repetitions. I know there are some postings on this site already but they seem to have a slightly different problem. I am searching for all permutations with repetitions. For example: combine(List('A','C','G')) Should yield: List(List('A'.'A','A'),List('A'.'A','C'),List('A'.'A','G'),List('A'.'C','A'), List('A'.'C',''C), ... List('G'.'G','G') I am sorry if my problem is already solved but I was not able to find it. Thanks in

All permutations with repetition using scala

落爺英雄遲暮 提交于 2020-01-12 17:30:43
问题 I am looking for the scala way to give all permutations without repetitions. I know there are some postings on this site already but they seem to have a slightly different problem. I am searching for all permutations with repetitions. For example: combine(List('A','C','G')) Should yield: List(List('A'.'A','A'),List('A'.'A','C'),List('A'.'A','G'),List('A'.'C','A'), List('A'.'C',''C), ... List('G'.'G','G') I am sorry if my problem is already solved but I was not able to find it. Thanks in

Assigning people to buildings while respecting preferences?

时光总嘲笑我的痴心妄想 提交于 2020-01-12 03:12:40
问题 A friend asked me a question today about an assignment problem. I found a quite straightforward solution, but I feel that it can be made simpler and faster. Your help would be appreciated. The problem: Assuming that I have N people, I need to assign them into M buildings, each building can house K people. Not all people are willing to live with each other, so i have a matrix of N*N cells and a 1 that marks the people that are willing to live with each other. If a cell contains 1 it means that

comparing numbers to sort then get median value

╄→гoц情女王★ 提交于 2020-01-11 09:36:09
问题 Sorting five integers using bitwise or comparison operators can be achieved by first getting the highest number then the second highest then the third and so on. Here is my code in getting the highest number: #include <stdio.h> int main() { int a, b, c, d, e; int aa, bb, cc, dd, ee; a = 4; b = 2; c = 5; d = 1; e = 3; aa = (a > b) ? ((a > c) ? ((a > d) ? ((a > e) ? a : e) : ((d > e) ? d : e)) : ((c > d) ? ((c > e) ? c : e) : ((d > e) ? d : e))) : ((b > c) ? ((b > d) ? ((b > e) ? b : e) : ((d >

N choose N/2 sublists of a list

馋奶兔 提交于 2020-01-11 06:36:06
问题 Is there an efficient way in Python to get all partitions of a list of size n into two subsets of size n/2 ? I want to get some iterative construct such that each iteration provides two non-overlapping subsets of the original list, each subset having size n/2 . For example: A = [1,2,3,4,5,6] # here n = 6 # some iterative construct # in each iteration, a pair of subsets of size n/2 # subsets = [[1,3,4], [2,5,6]] for example for one of the iterations # subsets = [[1,2,5],[3,4,6]] a different

Python: find all possible word combinations with a sequence of characters (word segmentation)

时光毁灭记忆、已成空白 提交于 2020-01-11 06:17:08
问题 I'm doing some word segmentation experiments like the followings. lst is a sequence of characters, and output is all the possible words. lst = ['a', 'b', 'c', 'd'] def foo(lst): ... return output output = [['a', 'b', 'c', 'd'], ['ab', 'c', 'd'], ['a', 'bc', 'd'], ['a', 'b', 'cd'], ['ab', 'cd'], ['abc', 'd'], ['a', 'bcd'], ['abcd']] I've checked combinations and permutations in itertools library, and also tried combinatorics. However, it seems that I'm looking at the wrong side because this is