Jump to content
Server Maintenance This Week. ×

list of unique combinations?


This topic is 5118 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hello

I'm trying to produce a list of all possible unique combinations from another list.

The order does not matter.

For example:

combinaisons_uniques (a, b, c, d) will return :

a, b, c, d

a, b, c

a, b, d

a, b

a, c

a, d

a, c, d

b, c, d

b, c

b d

b

c, d

c

d

any Idea?

Edited by Guest
Link to comment
Share on other sites

There is no apparent need to go recursive here since the number of combinations is down to 16 (15) - making it recursive involves an overhead and safeguarding not needed here.

The function can then by and large be writen like you have put it, including a pilcrow at the end of each line...

Where is the real problem here?

--sd

Link to comment
Share on other sites

no, it could be from 2 to 10 items in the list.

I found a java source :

http://stackoverflow.com/questions/403865/algorithm-to-sum-up-a-list-of-numbers-for-all-combinations

http://www.briandunning.com/cf/1023

unique_combinations_counter (number_values)

Edited by Guest
Link to comment
Share on other sites

Usage:

ListCombinations("a¶b¶c¶d", ", ")

Custom Function: (uses recursion)

ListCombinations(listOfValues; separator) =

Let(

[

listLength = ValueCount(listOfValues);

lastValue = GetValue(listOfValues; listLength);

lesserList = Case(

listLength > 1; ListCombinations(LeftValues(listOfValues; listLength - 1); separator);

""

)

];

Case(

listLength = 0; "";

listLength = 1; RightValues(listOfValues; 1); /* Ensures ¶ at end */

lastValue & "¶" &

lesserList & /* already terminated by ¶ */

Substitute(lesserList; "¶"; separator & lastValue & "¶")

)

)

Edited by Guest
Link to comment
Share on other sites

  • 3 weeks later...

Hello

I'm trying to produce a list of all possible unique consecutive combinations from another list.

The order does matter.

For example:

combinaisons_uniques (a, b, c, d) will return ;)

a,b,c,d

a,b,c

a,b

a

b,c,d

b,c

b

c,d

c

d

any Idea?

Link to comment
Share on other sites

Whats wrong with the last reply you got in this direction?

http://fmforums.com/forum/showtopic.php?tid/214260/post/354242/hl//fromsearch/1/#354242

...is it just the sortorder that makes it wrong?

--sd

Link to comment
Share on other sites

This situation is different from the older one in that each result in the list must contain sequential letters from the original sequence without skipping a letter.

Notice that "b, d", "a, d", and so on are not in the list as they were in the older post.

From what I can tell, this is essentially the result of Middle("abcd", n, m) where n and m are appropriately chosen and commas are added.

In designing the function I would use MiddleValues("a¶b¶c¶d"; n;m) and substitute "¶" for "," at the end.

Link to comment
Share on other sites

This works with the caveat that it produces some duplicates in the results. (Maybe someone can suggest a tweak that prevents the duplicates.)

ListSequences("a¶b¶c¶d"; ",") yields

a,b,c,d

a,b,c

a,b

a

b

b,c

b

c

b,c,d

b,c

b

c

c,d

c

d

// ListSequences(listOfValues; separator)

Let(

[

listLength = ValueCount(listOfValues);

properList = RightValues(listOfValues; listLength) /* Ensures ¶ at end */

];

Case(

listLength = 0; "";

listLength = 1; properList;

Substitute(

Left(

properList;

Length(properList) - 1); "¶"; separator) & "¶" &

ListSequences(LeftValues(properList; listLength-1); separator) &

ListSequences(RightValues(properList; listLength-1); separator)

)

)

Edited by Guest
Link to comment
Share on other sites

This topic is 5118 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.