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 ...
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 ...
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 ...
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:
...
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 ...
22
votes
4
answers
21k
views
Finding all k-subset partitions
The following code generates all \$k\$-subsets of a given array. A \$k\$-subset of set \$X\$ is a partition of all the elements in \$X\$ into \$k\$ non-empty subsets.
Thus, for ...
7
votes
4
answers
3k
views
Generating Permutations in Python
To brush up my Python knowledge I an algorithm to generate permutations in lexicographic order. I ended up with the following code:
...
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, ...
1
vote
2
answers
134
views
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.
...
19
votes
4
answers
5k
views
Count number of ways to paint a fence with N posts using K colors
A friend sent me this question, and I'd love somebody to review this and give his opinion.
Write an algorithm that counts the number of ways you can paint a
fence with N posts using K colors such ...
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
...