2

I've been looking at this and I thought there might be a pattern but I can't seem to find it. There are always $4$ elements, and they can be divided into $1, 2, 3, 4$ subsets ("chunks"). For example $$ S = \{ a, b, c, d \} $$ I want a function with the properties: \begin{align} f(1, S) &= \{ \{a, b, c, d \} \} \\ f(2, S) &= \{ \{ a \}, \{ b, c, d \} \} \\ f(3, S) &= \{ \{ a \}, \{ b, c \}, \{ d \} \\ f(4, S) &= \{ \{ a \}, \{ b \}, \{ c \}, \{ d \} \} \end{align}

I've been looking at it but I can't seem to find a rule that will produce the sequence of lengths. I'm looking for. Any ideas?

mvw
  • 34,562
Max
  • 123
  • may I ask why? I just need a mathematical rule that will give me those results for that specific input. that fact that will be used in a programming language can be ignored. – Max Dec 23 '14 at 15:31
  • 1
    Why doesn't 2 chunks generate $(ab,cd)$ – Ross Millikan Dec 23 '14 at 15:31
  • 1
    What would your desired sequences look like if you started with 5 elements? – davidlowryduda Dec 23 '14 at 15:32
  • @RossMillikan - that's the desired output, it's not a mistake. Would have been a bit easier I guess if it was (ab, cd) – Max Dec 23 '14 at 15:33
  • @mixedmath - at the moment the sequence can have less than 4 elements but not more than 4. So for more than 4 I don't have an issue at the moment. – Max Dec 23 '14 at 15:34
  • You haven't defined the desired output clearly enough. Do you want all ways to divide the string into $n$ chunks? Or just one for each size $n$? – Ross Millikan Dec 23 '14 at 15:53
  • @RossMillikan just one for each size n. – Max Dec 23 '14 at 15:58
  • Then which one? For $m$ elements in the list, there are ${m-1 \choose n}$ choices – Ross Millikan Dec 23 '14 at 16:03
  • @RossMillikan There are always 4 elements. So I'm not sure I understand your question. – Max Dec 23 '14 at 16:07
  • Why is this question on hold? I don't see how I can be more specific. I've clearly stated what the input is, what the desired output is for a selected number of chunks. The number of sets is always 4. Henning Makholm provided a good answer, but I just need a formula. So which point specifically is not clear enough? – Max Dec 23 '14 at 16:14

1 Answers1

1

There are lots of imaginable principles that would lead to the partitions you show, but you don't have nearly enough data to choose in a principled way which of them is the once you need in your (undisclosed) application.

For example, if you had 10 elements instead of four, the first few patterns could be

abcdefghij
a,bcdefghij
a,bcdefghi,j
a,b,cdefghi,j
a,b,cdefgh,i,j
a,b,c,defgh,i,j

or

abcdefghij
a,bcdefghij
a,bc,defghij
a,bc,def,ghij
a,b,c,def,ghij
a,b,c,def,ghi,j

or even

abcdefghij
a,bcdefghij
a,bc,defghij
a,b,c,defghij
a,b,c,de,fghij
a,b,c,d,e,fghij

All of these generalize your 4-element division in a relatively straightforward way -- do you have any information that would allow you to judge which of these straightforward ways is better?

  • I don't think there will be more than 4 elements and I can explain why. This set will contain address parts (street, number, city, county). Like I said before, it can have less, but not more. And this address can be split on 1, 2, 3 or 4 lines (or chunks in my question). I just abstracted the problem thinking it would be easier to find a pattern. So I think the 2nd and 3rd pattern looks compatible. Is there a formula that can be extracted that takes into account the number of chunks and produce the results you've outlined? – Max Dec 23 '14 at 16:03
  • @Max: In that case, "first abcd, then a-bcd, then a-bc-d, then a-b-c-d" is a perfectly cromulent way of expressing the pattern, and trying to shoehorn it into something that looks like there's a "formula" or deeper principle involved would just make it harder to figure out what the code is doing, without giving you any benefit at all over just hardcoding it directly (or using a table). – hmakholm left over Monica Dec 23 '14 at 16:23
  • Thanks @HenningMakholm. I guess I just needed a confirmation that hardcoding is just as good. For a second I thought there might be a pattern in there. – Max Dec 23 '14 at 16:30