I need to find the possible permutations (hope that is the right terminology) given a set of items N where order is important and I'm looking for permutations with M number of consecutive items from N while also satisfying the condition that the number of pairings must be P.

An example of this would be having N=4 items 1,2,3,4 and needing to pair these into P=3 groups whil resepcting the order, this would give [1 , 2-3, 4], [1-2 ,3 ,4], [1 , 2 , 3-4].

M here can only be 1 or 2 if I have this right.

  • $\begingroup$ I don't think you mean permutations. Permutations are are rearrangements, but you always keep the numbers in the same order. I can't understand what you mean by $M$ and $P$. You first say that $P$ is the number of pairings, and then that it is the number of groups. Which is it? What does "$M$ number of consecutive items" mean? In the problem description, it sounds like $M$ is given, but in your example, you says it can be $1$ or $2$. Please try to restate your question more clearly. $\endgroup$ – saulspatz Aug 6 at 15:22
  • $\begingroup$ Thank you for the clarification and the answer, I struggled with putting the probelem into writing. What I meant by P is the number of groups, in my example it is 3 so there has to be 3 groups of items, M I guess is not useful here but what I meant by it is that if we had 3 items in my example and P was 3 then M has to be 1. if N was 5 then M can be 3 since you can have [123,4,5]. M is useful for the specfic application I'm using this for since I want to be able to tune it as well. $\endgroup$ – Alla Aug 6 at 15:26

If I understand the question what you have to do is choose $P-1$ places in the list $$ 1-2-3 - \cdots - N $$ where you change the $-$ to a $,$ to build the list of groups (in your notation).

So the answer is the binomial coefficient $\binom{N-1}{P-1}$

For example, if $P=4$ and $N=7$ there will be $\binom{6}{3} = 20$ ways. One of them is $$ 1 - 2 , 3 - 4 - 5 , 6, 7 $$

You can look up binomial coefficient in wikipedia.

  • $\begingroup$ Thank you Ethan, I tried to look into this before posing here but I was a bit overwhelmed, I will read up on binomial coefficients. this does seem to answer the question, I'll just be left with the task of listing those possible ways. $\endgroup$ – Alla Aug 6 at 15:38
  • $\begingroup$ @Alla Many computer languages have packages with methods that cab help with this. $\endgroup$ – Ethan Bolker Aug 6 at 15:47
  • $\begingroup$ Thank you for your valuable input, I will look into those as well and I'm assuming adding the constraint of M is not possible or at least difficult, as in specifying that a group can not exceed M number of items, in your example setting M at 2 making the 2-3-4 group invalid. $\endgroup$ – Alla Aug 6 at 15:50
  • $\begingroup$ @Alla With a maximum of $M$ in each group I think the problem is more difficult. (Your question did not make the meaning of $M$ clear.) $\endgroup$ – Ethan Bolker Aug 6 at 15:54
  • $\begingroup$ That is correct, I did not phrase it well, nonetheless your input has been valuable and I have an idea where to look for now. $\endgroup$ – Alla Aug 6 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.