# Tag Info

Accepted

### Efficient lazy weak compositions

Chunks of weak compositions Here is slightly modified version of algorithm used in CombinatoricaNextComposition converted to a ...
• 14.7k

### Partitioning with varying partition size

New in 11.2 is TakeList: TakeList[Range[10], {2, 3, 5}] {{1, 2}, {3, 4, 5}, {6, 7, 8, 9, 10}}
• 122k

### Partitioning a number into consecutive integers

The sum of consecutive numbers from $a$ to $b$ is $$\frac{(a+b)(b-a+1)}{2}$$ hence simply ...
• 23.2k
Accepted

### How to split a number

You can also use NumberDecompose with the basis {10000, 100, 1}: ...
• 348k

### Improving speed of code computing number of nonrepeating partitions

Here is a summary of comments (before @ciao's best answer above), with a change in notation. These functions calculate the number of partitions of n into exactly <...
• 14.8k
Accepted

### Improving speed of code computing number of nonrepeating partitions

This seems pretty quick, particularly on larger cases / larger k, e.g. 451, 29, 101 finishes in a few seconds on the loungebook. N.B. - I have not tested this ...

### Partition a list by count of a number

It is always good to start with System functions: Flatten /@ Partition[Split[list, #1 =!= 2 &], UpTo[3]] ...
• 132k

### Is there concise code for the list operation I want to perform?

Li = Range[5]; TakeDrop[Li, #] & /@ Range[Length[Li]-1] // Column[Row/@#]& or, slightly shorter, ...
• 348k
Accepted

### How to generate all possible orderless partitions of a list according to another list?

A solution using Repeated, ReplaceList, and the Orderless attribute. ...
• 264k

### Improving speed of code computing number of nonrepeating partitions

Here is a totally different approach based on the fact that successive products forming the generating function are due to multiplication by a binomial $1+t*z^j$. Form a matrix $v$ of zeros with $n+1$ ...
• 14.8k
Accepted

...
• 64.4k

### Partitioning with varying partition size

This can be implemented elegantly with FoldPairList and TakeDrop (both new in v10.2), in fact it's one of the examples in the ...
• 5,559

### How to generate all possible orderless partitions of a list according to another list?

Permutations treats repeated elements as identical, so you can get a flattened version of the desired result with something like ...
• 83.2k
Accepted

### Partitioning an image based on features

You can use ImageTrim to extract the bounding boxes from the image. ...
• 83.2k

### Is there concise code for the list operation I want to perform?

This is literally the canonical example from the ReplaceList documentation: ...
• 264k
Accepted

### Index-based Array splitting

For the simple case of even and odd, you can do either: ...
• 86.8k

### While partitioning the elements in a list using GatherBy, can I correspondingly partition the elements of an unrelated list?

Here is another approach. The basic idea is that GatherBy creates a list of representatives corresponding to the input, then partitions the input based on those ...
• 122k
Accepted

### Goldbach Partition

Take a look at IntegerPartitions, although it relies on brute-force enumeration that is unlikely to scale well. ...
• 264k

### Any alternative way to compute IntegerPartitions?

There are 190,569,292 unrestricted integer partitions of 100 (PartitionsP@100). This will need >1gb of RAM just to keep the final result. You can generate them in ...
• 25k

### How to generate all possible orderless partitions of a list according to another list?

It's far from pretty, using pattern matching (OrderlessPatternSequence): ...
• 14.6k

...
• 5,709
Accepted

### Merge list repeating elements

lst = {{{a, b}, {c, d}}, {{e, f}, {h, i}}}; You can use Tuples or Outer or ...
• 348k
Accepted

### Partitioning a number into consecutive integers

I took it as a challenge to avoid using Solve, which can be slower than a direct assault. If $a$ is the first number in the sum of consecutive positive integers, ...
• 14.8k

### How can I extract parts from a ragged nested list?

Using Part you could do something like the following: ...
• 7,299

### generating integer partitions

I needed to do this sometime ago while investigating Bell polynomial analogs. Normally, you'd do FrobeniusSolve[Range[n], n] but the fastest variation (and quite ...
Accepted

### GatherBy/SplitBy and Sort a list

As noted by @SimonWoods in the comments, using #.#& instead of Norm gives a huge speed up. ...
• 348k

### How to split a number

DateList[{IntegerString @ #, {"Year", "", "Month", "", "Day"}}][[;; 3]] & @ 19001231 ...
• 348k

### Any alternative way to compute IntegerPartitions?

You may use PartitionsP to skip calculating the partitions. This will improve performance "infinity-fold" (in practical terms) for the integer frequency counts on ...
• 39.3k

### Partitioning a set of integers

Split[{1, 2, 3, 6, 7, 9, 10}, #2 - #1 == 1 &] {{1, 2, 3}, {6, 7}, {9, 10}}
• 6,425