Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

list of unique combinations?

Featured Replies

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

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

  • Author

the real problem is that i don't know how to do... :-(

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

  • Author

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

Although I spotted you missed out a combination, could it be witten this way:

--sd

Benka.zip

  • Author

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.

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

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

  • Author

:goodpost:

:jaw:

It works! Thanks a lot! :thankyou:

Edited by Guest

:clap: :worship:

--sd

  • 3 weeks later...
  • Author

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?

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

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.

Ah yes I now as well spotted the difference - :bang:

--sd

I think the custom function described here provides most of this functionality.

That function has duplicate entries and doesn't separate by commas, but it does provide a starting point.

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

  • Author

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.

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.