All Questions
Tagged with combinatoricspython
157 questions
1vote
1answer
1kviews
Print the lexicographically smallest permutation that satisfies the given formation
Problem Statement: A DOTA game has N heroes, each with a distinct rank from [1..N]. In DOTA every formation is characterized as a permutation [1...N] of ranks of players. A formation is Imba ...
4votes
2answers
126views
Find only one subset sum with a specified value for large sets
How can I optimize my code for a large set (10,000 elements)? ...
4votes
3answers
178views
Two strings are permutations of each other
I am trying to remove the characters from the list generated from the second string. At the end, if the array is empty, it is the permutation of two strings, else it is not. Is this logic fine? ...
6votes
1answer
495views
Python knapsack program
I have this data for the knapsack problem: List of product prices = MENU Most popular product count = MOST_POPULAR_COCKTAIL ...
1vote
1answer
106views
Finding the number of distinct decompositions a number has using only repdigits
This is a problem from a previous semester that I am trying to upsolve. I am trying to solve a problem involving the total number of ways of decomposing a number using only repdigits. A repdigit is a ...
3votes
2answers
184views
Find the join of two set partitions
Two partitions of a set have a greatest lower bound (meet) and a least upper bound (join). See here: Meets and joins in the lattice of partitions (Math SE) The meet is easy to calculate. I am trying ...
3votes
1answer
82views
Number of partitions of (a,b) into k distinct parts which sum up to (a,b)
Problem set This is somewhat a generalization of the famous partition of integer n into k parts. Given two integers ...
8votes
3answers
294views
Refactor the code which performs "cross-product", "reduce", "product of list" and "sum of list"
I have come up with a sequence of steps to find the maximum product of y positive numbers which add up to x. But the program is ...
4votes
1answer
129views
Repetition-Limited Multiset Coefficient function
This is a simple multiset coefficient calculator in python, that will calculate both standard multiset coefficients, as well as multiset coefficients with repetition limits, used initially as part of ...
6votes
2answers
108views
Schedule a series of 1:1 contests so that each entrant plays against every other
My sister is organizing a Majong tournament. She wants to set up a set of round-robin rounds. There will be 16 players at 4 tables; 4 players per table. Players will play 5 rounds. She wants every ...
2votes
1answer
154views
Find the list of combination (with repetition) given rank and number of items. (Lexicographic ordering)
The problem involves the fastest possible method to generate a list of combinations which repeats from all the possible combinations with repetition allowed. I know there needs to be a way to ...
1vote
1answer
126views
Effective encoding-decoding chain determination (time optimization)
Could you please help with speeding-up this code? Input: UTF-8 text (encoded 1-3 times from known pool of encodings). Every time was encoded and decoded by random encoding from pool. Original was koi8-...
7votes
2answers
1kviews
Find all combinations of length 3 whose sum is divisible by a given number
I came up with a suitable solution to a HackerRank problem that failed because the execution took longer than 10 seconds on lists that were of very large size. The problem: Given a list ...
8votes
2answers
949views
Print all "balanced" sequences of 'A' and 'B'
the aim of the code below is to print all balanced sequences with equal number of 'A' and 'B'. A sequence is balanced if every prefix of length \$\geqslant 4\$ is balanced. A prefix is balanced if the ...
3votes
0answers
58views
Check if two semistandard Young tableaux are compatible
I have a question about how to check if two tableaux are compatible (will define below). Here we only consider tableaux of rectangular shape. A tableau is called semistandard if its rows are weakly ...