combinatorics

How to get the correct answers from a permutation / combination problem?

How to get the correct answers from a permutation / combination problem? Question: Given the following input, I would like to implement a function, that calculates the amount of possible correct answers, without calculating each answer for computational reasons. I hope the function to look something like this: from itertools import combinations_with_replacement from itertools import …

Total answers: 1

All possible integer array of fixed length for a given norm?

All possible integer array of fixed length for a given norm? Question: Given d and t, positive integers, i would like to generate all possible 1D arrays of length d such that coordinates are positive integers and their sum is less or equal to t. For example, for d=2, and t=2, such possibilities are : …

Total answers: 1

Is there an efficient method of limiting sets of unique combinations of two lists in Python?

Is there an efficient method of limiting sets of unique combinations of two lists in Python? Question: I have the following code to generate each set of unique combinations between two lists. Alternatively phrased, all possible sets of matches of targets from a list of sources. from itertools import permutations def combos(sources, targets): assert len(sources) …

Total answers: 1

Meal plan algorithm closest to x calories with types

Meal plan algorithm closest to x calories with types Question: I have a problem where I need to generate a meal plan with: x number of meals per day (eg. 5) x number of meal types in the plan (eg. 2 breakfasts, 2 snacks and 1 lunch) Number of calories in meal plan (eg. 2000) …

Total answers: 1

Python: Extract all possible mutually exclusive pairs?

Python: Extract all possible mutually exclusive pairs? Question: I have an assignment problem where I have N participants and need to find all possible 2-person assignments where every participant is assigned to exactly one pair. When I use list(combinations(range(100), 2)) I get a "flat" list of about 4000 items, each a pair in the form …

Total answers: 2

How can I combine 2 lists in a specific order?

How can I combine 2 lists in a specific order? Question: This is an example for 3 elements List_A = [‘abc’, ‘def’, ‘ghi’] List_B = [‘123’, ‘456’, ‘789’] for i in [List_A[0], List_B[0]]: for j in [List_A[1], List_B[1]]: for k in [List_A[2], List_B[2]]: print(i+j+k) Following this result: abcdefghi abcdef789 abc456ghi abc456789 123defghi 123def789 123456ghi 123456789 …

Total answers: 1

Dynamically brute-force all numerical combinations

Dynamically brute-force all numerical combinations Question: As the title says I’m trying to get all possible numerical combinations for an unknown number of parameters. I don’t mind if you use pandas or numpy. See the code section to understand my problem easily. Any help would be appreciated. # n can be any integer. 4 is …

Total answers: 1

How to code a factorial matrix combination in Python

How to code a factorial matrix combination in Python Question: Consider the following input matrix (- are arbitrary values): A B C D E F A – – – – – – B – – – – – – C – – – – – – D – – – – – – E – …

Total answers: 1