this tag is used for questions regarding splitting a list into sublists
Questions tagged [partitions]
169 questions
6
votes
5 answers
How can I extract parts from a ragged nested list?
I have given the following list
list = {a, {b, c, d, e}, {e, f, h, i}}
Is there a direct way to use Part specification to get e.g. {a,b,e} or {a,c,f}. I know about Flatten or Append of course, but want to avoid it in my specific case.
Something…
NeverMind
- 1,201
- 7
- 9
6
votes
3 answers
How to find most complete partition of a list
How to find most complete partition of a list?
For example:
list1={5,8}
list2={4,4,2,3,6}
8 can be comprised of {4,4} or {2,6}
But 5 can only be comprised of {2,3}
If I choose {2,6} for 8 , there is no combination for 5 in list2.
How can I get…
goldmonkey
- 161
- 3
5
votes
1 answer
Partition With Offset
I have the following two lists:
{a,b,c,d,e,f} and {x,y,z}
and would like to use Partition to create groups of the form:
{a,x}, {b,y}, {c, z}
My first approach is to use:
list1 = {a,b,c,d,e}
list2 = {x,y,z}
flat = Flatten[{list1, list2}]
The output…
dixontw
- 441
- 2
- 4
5
votes
5 answers
Get a List With `Partition`
How can I add two brackets for a sublists of Length 2 ?
Objective:
{{{1, 2}}, {{3, 4}}, {{5, 6}}, {{7, 8}}, {{9, 10}}, {{11, 12}}, {{13,
14}}, {{15, 16}}, {{17, 18}}}
The code I write here only give only 1 bracket for a sublist of length…
kile
- 1,671
- 5
- 10
5
votes
2 answers
Integer partitions in all orderings
I want to partition an integer into $k$ integers all possible orderings. This can be done in the following way
integerPartitions[n_, {k_}] := Select[FrobeniusSolve[Table[1, {k}], n], FreeQ[#, 0] &]
For example,
integerPartitions[4, {2}]
gives…
unstable
- 1,497
- 15
- 14
4
votes
2 answers
Partition with offset and varying size
Assume I have the list below.
list=Range@20;
Desired partition is:
{{1,2,3,4},{4,5,6,7,8},{8,9,10,11,12},{12,13,14,15,16},{16,17,18,19,20}}
I have tried
Partition[Range@20, 4, 3]
and
FoldPairList[TakeDrop, Range@20, Range[4, 6]]
does not…
OkkesDulgerci
- 10,716
- 1
- 19
- 38
4
votes
1 answer
A partition problem
I want to find all partitions of the set $\{1,2,\ldots,40\}$ into disjoint sets $A$ and $B$ such that no subset of $B$ has a sum that is a member of $A$?
I have an algorithm for doing this although it is too slow for a set this size. Is anyone aware…
Auslander
- 173
- 4
3
votes
2 answers
Partitioning values in a sequence
I have a sequence that forms visible lines when plotted as a graph, what would be a good way to automatically partition the sequence to create a list of sequences, one for each line that is visible when the sequence is plotted?
Here is the start of…
Jamie M
- 503
- 2
- 7
3
votes
1 answer
Non-Constant Partitioning of a List with Order Analysis
Let's say I have a set of numbers "r" whose sum equals 15, and I want to randomize all values up to and including that sum from and including 1 into a set called "a". So far I have this:
r = {4,5,6}
ord = Range[15]
a = RandomSample[ord]
And though…
Travis Arlen McCracken
- 149
- 8
2
votes
4 answers
Express integer as a sum of specific integers from a set, using each no more than once
I know there's a way to find partitions of an integer as a sum like:
IntegerPartitions[12,All,{1,4,7}]
which returns
{{7, 4, 1}, {7, 1, 1, 1, 1, 1}, {4, 4, 4}, {4, 4, 1, 1, 1, 1}, {4, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}…
Raksha
- 633
- 1
- 6
- 19
2
votes
2 answers
Partition vector
I have a vector composed of 10 elements and I want to "split" it into two vectors composed of five elements:
q={1,2,3,4,5,6,7,8,9,10};Partition[q,5]
but the output is a matrix...
{{1,2,3,4,5},{6,7,8,9,10}}
How can I obtain 2 separated vectors…
Gae P
- 637
- 3
- 11
0
votes
0 answers
code for Garsia-Milne bijection
The combinatorial interpretation of the first Rogers-Ramanujan identity states that the partitions of n with gaps at least two between parts and the partitions of n with parts that are either 1 or 4 modulo 5 have the same size. In their 1982 paper…
user38230
- 1
- 1