# Help with n-Distinct Integer Partitions

Posted 9 years ago
2479 Views
|
2 Replies
|
5 Total Likes
|
 IntegerPartitions displays all the partitions of nSelect[IntegerPartitions[5], Max[Length /@ Split@ #] == 1 &] gives me partitions where each element is at least 1 apart (or distinctI am trying to find a way to get all the partitions where each element is at least 2 apart, then i want to be able to generalize it to n apart.for example 4 has two that is two apart because it contains {4} and {1,3}. Any help would be greatly appreciated
2 Replies
Sort By:
Posted 9 years ago
 Could do this with Reduce, as below. f[n_, j_] := Module[   {vars, x, vals, solns},   res = Table[     vars = Table[x[l], {l, k, n, j + 1}];     vals = Map[First, vars];     Print[{k, vars}];     Print[Prepend[Map[0 <= # <= 1 &, vars], vars.vals == n]];     solns = vars /.       Solve[Prepend[Map[0 <= # <= 1 &, vars], vars.vals == n], vars,       Integers];    solns = Map[vals*# &, solns];    solns /. 0 :> Sequence[]    , {k, j}];  res  ]For example:In[211]:= f[7, 1]Out[211]= {{7}, {3, 4}, {2, 5}, {1, 6}, {1, 2, 4}}In[213]:= f[11, 2]Out[213]= {{11}, {4, 7}, {3, 8}, {2, 9}, {1, 10}, {1, 4, 6}, {1, 3, 7}}There may also be an approach via generating functions.
Posted 9 years ago
 Use ListConvolve on the sorted list is helpful: In[4]:= Cases[IntegerPartitions[10],x_/;Length[x]>=2 && Min[ListConvolve[{-1,1},x]] >= 2]Out[4]= {{9,1},{8,2},{7,3},{6,4},{6,3,1}}ListConvolve with kernel {-1,1} computes the difference of the adjacent elements through the lexicon-reversely-ordered list. If the min value of the new list is larger than 2, I know each pair is at lease 2 apart.