April 9, 201015 yr 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 April 9, 201015 yr by Guest
April 9, 201015 yr 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
April 9, 201015 yr 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 April 9, 201015 yr by Guest
April 9, 201015 yr 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 April 9, 201015 yr by Guest
April 9, 201015 yr Although I spotted you missed out a combination, could it be witten this way: --sd Benka.zip
April 9, 201015 yr 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.
April 9, 201015 yr 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 April 9, 201015 yr by Guest
April 9, 201015 yr 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 April 9, 201015 yr by Guest
April 9, 201015 yr Author :goodpost: It works! Thanks a lot! :thankyou: Edited April 9, 201015 yr by Guest
April 29, 201015 yr 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?
April 29, 201015 yr 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
April 29, 201015 yr 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.
April 29, 201015 yr 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.
April 29, 201015 yr 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 April 29, 201015 yr by Guest
April 30, 201015 yr 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