Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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

Recommended Posts

Posted (edited)

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
Posted

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

Posted (edited)

Your example list has 4 items.

Do you know in advance if all of the lists for your custom function will have 4 items?

If it can be different from 4, is there a maximum number of items it will have?

Edited by Guest
Posted (edited)

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
Posted

Thanks.

But there is a problem.

With 4 items, there are 15 combinations, but

with 7 items, there are 127 combinations...

I'm trying to make a custom function to do this.

Posted (edited)

Ah yes then it begins to make sense to make it recursive instead.

But it was a little unclear in the beginning of the thread!

--sd

Edited by Guest
Posted (edited)

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
  • 3 weeks later...
Posted

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?

Posted

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

Posted

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.

Posted (edited)

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
Posted

Hello

Thank you all for your answers!

Sorry for the response time ;) I'm in France.

I'll try to implement a duplicate management in this function.

This topic is 5332 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.