7 Replies Latest reply: Sep 2, 2010 10:29 AM by 800282 RSS

    Combinations Algorithm

    843853
      I have a few Lists of Strings. for example:

      List<String> AList contains {"a1","a2","a3","a4"}
      List<String> BList contains {"b1","b2","b3"}
      List<String> CList contains {"c1","c2","c3","c4","c5"}
      List<String> DList contains {"d1","d2"}

      so on and so forth. The number of lists is variable and number of Strings in the list is also variable. I want to write a code that returns ALL POSSIBLE combinations under the following conditions:

      1) each set contains at least two elements. In this example the each set will contain 2 to 5 elements. - example: {"a1","b1"} or {"c2","b3","d2"}
      2) each element in a set is from different lists - example: {"c1","c4"} or {"b1","b2","a4"} both are invalid.
      3) each set has unique combination of elements - example: {"a3", "d2", "b4"} is equivalent to {"d2", "a3", "b4"} hence if {"a3", "d2", "b4"} is returned in the results {"d2", "a3", "b4"} should not be returned.

      I am using Java.
        • 1. Re: Combinations Algorithm
          796262
          Okay, and what's your question? We can't really answer general "how do I do this" type questions other than by pointing you to the basic tutorials.

          Post some code, in SSCCE form, demonstrating where you got stuck. Ask a specific question.

          PS- Am I reading it right that you registered 10 years ago, but only made your first post now?
          • 2. Re: Combinations Algorithm
            843853
            Cross posted - [http://www.coderanch.com/t/508944/java/java/Combinations-Algorithm|http://www.coderanch.com/t/508944/java/java/Combinations-Algorithm].
            • 3. Re: Combinations Algorithm
              843853
              Can I see those basic tutorials?

              You are correct about the PS. Thanks to hardworking people like you I never had to ask an original questions before.
              • 4. Re: Combinations Algorithm
                796262
                bvphadnis wrote:
                Can I see those basic tutorials?
                Sure. A quick google of "java tutorial" came up with this, which is full of great information.
                You are correct about the PS. Thanks to hardworking people like you I never had to ask an original questions before.
                Interesting. Surely in that time you've also seen how people respond to general "how do I do this" type questions and especially cross-posting?
                • 5. Re: Combinations Algorithm
                  843853
                  kevinaworkman If you do not want to help can you please stay off this? This is nonsense.
                  • 6. Re: Combinations Algorithm
                    796262
                    bvphadnis wrote:
                    kevinaworkman If you do not want to help can you please stay off this? This is nonsense.
                    Nice attitude. I would love to help, but this isn't a code factory. You have to show some initiative before anybody here is going to help you. We aren't going to do your homework for you, but if you ask a specific question and show an SSCCE, then I or another poster is sure to help you out. You can choose to continue your tantrum instead, but I guarantee that you'll be even less likely to receive help if you do. Doing things like not posting an SSCCE, cross-posting, and whining when somebody asks you where you're stuck are surefire ways to be added to ignore lists. If you've been here for 10 years, you should know all of this by now.

                    Care to try again?
                    • 7. Re: Combinations Algorithm
                      800282
                      bvphadnis wrote:
                      kevinaworkman If you do not want to help can you please stay off this? This is nonsense.
                      Yeah, that type of responses will surely attract people willing to give you a hand.