2
$\begingroup$

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?

$\endgroup$
10
  • $\begingroup$ 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. $\endgroup$
    – Max
    Dec 23, 2014 at 15:31
  • 1
    $\begingroup$ Why doesn't 2 chunks generate $(ab,cd)$ $\endgroup$ Dec 23, 2014 at 15:31
  • 1
    $\begingroup$ What would your desired sequences look like if you started with 5 elements? $\endgroup$
    – davidlowryduda
    Dec 23, 2014 at 15:32
  • $\begingroup$ @RossMillikan - that's the desired output, it's not a mistake. Would have been a bit easier I guess if it was (ab, cd) $\endgroup$
    – Max
    Dec 23, 2014 at 15:33
  • $\begingroup$ @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. $\endgroup$
    – Max
    Dec 23, 2014 at 15:34

1 Answer 1

1
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ 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? $\endgroup$
    – Max
    Dec 23, 2014 at 16:03
  • $\begingroup$ @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). $\endgroup$ Dec 23, 2014 at 16:23
  • $\begingroup$ 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. $\endgroup$
    – Max
    Dec 23, 2014 at 16:30

Not the answer you're looking for? Browse other questions tagged .