All Questions
36 questions
3
votes
2
answers
184
views
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 ...
3
votes
1
answer
83
views
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 ...
7
votes
2
answers
1k
views
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 ...
1
vote
1
answer
90
views
An algorithm that minimizes the number of ingredients necessary
I am working on a code that will minimize the number of ingredients necessary to make some dishes.
Each dish can be prepared in an arbitrary large number of ways, with combinations of two ingredients. ...
1
vote
1
answer
130
views
Subset Product Algorithm
Subset Product is an NP-complete problem and is my favorite problem. So, I've written a slightly smarter way of solving the problem.
Will performance impact matter if I use multi-cpus and my GPU?
Do ...
5
votes
2
answers
2k
views
Find non-overlapping pairs of elements in a list whose difference is less than some given threshold
I have the following task: Let us have a list (denoted by L, and for simplicity, the elements come from the interval [0,1]). We are given a parameter (denoted by C), and we want to find as many pairs ...
1
vote
2
answers
134
views
2
votes
1
answer
91
views
Count the different positions reached in a cycle of permutations
I have come across a problem on cyclic permutations. It is about swapping numbers around.
It starts out with input N < 100,000 which makes the first N natural numbers as orders: 1 2 3 ... N-1 N
...
4
votes
1
answer
93
views
Filter out unwanted substrings while generating all possible relevant substrings
Write a Program that determines where to add periods to a decimal string so that
the resulting string is a valid IP address. There may be more than one valid IP address
corresponding to a string, ...
8
votes
3
answers
294
views
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 ...
7
votes
2
answers
6k
views
Permutations with replacement in Python
Many a times, I've had the need to use a permutations with replacement function.
So, I've written a function to do just that:
...
7
votes
2
answers
3k
views
Sums of all sublists
The parts_sums function in the code takes a list as parameter and then returns sum of all sub-lists present in the list. e.g.
if, ...
5
votes
1
answer
2k
views
Project Euler 76: Counting summations
Project Euler Problem 76 asks:
How many different ways can one hundred be written as a sum of at least two positive integers?
My code is correct but just works slowly.
...
1
vote
1
answer
90
views
Algorithmic complexity of this algorithm to find all ordered permutations of length X
I have written a recursive function to generate the list of all ordered permutations of length X for a list of chars.
For instance: ['a', 'b', 'c', 'd'] with X=2 will give [['a', 'a'], ['a', 'b'], ['...
4
votes
2
answers
2k
views
Steinhaus-Johnson-Trotter Algorithm
I began to program a little while ago and tried to implement my first algorithm: the Steinhaus-Johnson-Trotter algorithm. This algorithm generates a sequence of permutations of \$n\$ elements such ...