Skip to main content

All 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 ...
Watchduck's user avatar
  • 230
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 ...
linuxbeginner's user avatar
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 ...
NFeruch - FreePalestine's user avatar
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 ...
Yozachar's user avatar
  • 227
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 ...
Atvin's user avatar
  • 153
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: ...
Sriv's user avatar
  • 2,790
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. ...
adrienlucca.net's user avatar
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 ...
The T's user avatar
  • 491
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 ...
spinning_plate's user avatar
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: ...
Nils's user avatar
  • 474
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, ...
Akhil Pandey's user avatar
1 vote
2 answers
134 views

Get the next bigger number by rearranging the digits of the input integer

...
Edmerson Pizarra's user avatar
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. ...
camarman's user avatar
  • 519
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 ...
thomas's user avatar
  • 293
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 ...
halcyon44's user avatar

15 30 50 per page