2 Replies Latest reply on Apr 29, 2010 8:51 AM by benka_1

    list of unique combinations?

    benka_1

      Title

      list of unique combinations?

      Post

      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
      has
      a, c, d
      b, c, d
      b, c
      b d
      b
      c, d
      c
      d

      any Idea?












        • 1. Re: list of unique combinations?
          davidanders

          Could you provide more information?

          Only four possibilites?

          Are they static or do they change?

          What is the purpose and would the users be confused?

          2 would mean 2tothe2ndpower or 4

          3 would mean 2to the3rdpower or 8

          4 would mean 2to the4thpower or 16

          It might be easier to do it once manually, unless they change.

          • 2. Re: list of unique combinations?
            benka_1

                In response to Søren Dyhr

            <!--  GALLERYINCLUDE  -->

            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 & "¶")
            )

            )
            <!--  POLLS  --><!--  FILES  --><!--  SIGNATURE  -->



            Edited by TheTominator on 09/04/10 04:37 PM. Reason for edit: No reason given.















            http://fmforums.com/forum/showpost.php?post/354242/

             

            09/04/10 04:34 PM - Post#354242<!--  IP  -->    <!--  NEWMARKER  --><!--  IS_MODERATED  --> - Post Rank:            

            <!--  POST_OPTIONS  --><!--  SPREED  -->