Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #37013

Re: What's the best way to make a cross string set?

From Knute Johnson <nospam@rabbitbrush.frazmtn.com>
Newsgroups comp.lang.java.programmer
Subject Re: What's the best way to make a cross string set?
Date 2017-07-27 15:34 -0500
Organization A noiseless patient Spider
Message-ID <oldihc$874$1@dont-email.me> (permalink)
References <6f9ff338-1944-4b64-83b8-4a921ce57a89@googlegroups.com> <oldftj$vac$1@dont-email.me> <95687d57-46ef-47d8-84de-505e79d67784@googlegroups.com>

Show all headers | View raw


On 7/27/2017 15:22, Eric Douglas wrote:
> On Thursday, July 27, 2017 at 3:50:08 PM UTC-4, Eric Sosman wrote:
>> recursive solution along the lines of:
>>
>> 	void tuples(List bigList, int which, String soFar) {
>> 	    if (which < bigList.size()) {
>> 	       for (Object item : bigList.get(which)) {
>> 	           tuples(bigList, which + 1, soFar + item);
>> 	       }
>> 	    } else {
>> 	        System.out.println(soFar);
>> 	    }
>> 	}
>> 	...
>> 	tuples(list1, 0, "");
>>
> 
> That doesn't make sense.  As is it doesn't compile, just says bigList.get(which) needs to return an Iterable.  I've tried modifying it but I'm not sure how it's supposed to work.
> 

import java.util.*;

public class test0 {
     public static void main(String... args) {
         List<String> list1 = Arrays.asList("a","b","c","d");
         List<String> list2 = Arrays.asList("1","2","3");
         List<String> list3 = Arrays.asList("fg","hj","kl");
         List<String> list4 = Arrays.asList("x","y");
         List<List<String>> list0 = new ArrayList<>();
         list0.add(list1);
         list0.add(list2);
         list0.add(list3);
         list0.add(list4);

         ArrayList<String> result = new ArrayList<>();
         GeneratePermutations(list0,result,0,"");

         System.out.println(result);
     }

     /* with a nod to StackOverflow */
     static void GeneratePermutations(List<List<String>>list,
      List<String> result,int depth, String current) {
         if (depth == list.size()) {
             result.add(current);
             return;
         }
         for (int i=0; i<list.get(depth).size(); i++) {
             GeneratePermutations(list,result,depth + 1,
              current + list.get(depth).get(i));
         }
     }
}



-- 

Knute Johnson

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-07-27 12:12 -0700
  Re: What's the best way to make a cross string set? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-07-27 14:38 -0500
    Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-07-27 12:49 -0700
  Re: What's the best way to make a cross string set? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-27 15:49 -0400
    Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-07-27 12:55 -0700
    Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-07-27 13:22 -0700
      Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-07-27 13:30 -0700
      Re: What's the best way to make a cross string set? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-07-27 15:34 -0500
      Re: What's the best way to make a cross string set? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-27 18:27 -0400
        Re: What's the best way to make a cross string set? lewbloch@gmail.com - 2017-07-28 18:51 -0700
    Re: What's the best way to make a cross string set? v_borchert@despammed.com (Volker Borchert) - 2017-07-29 06:03 +0000
  Re: What's the best way to make a cross string set? v_borchert@despammed.com (Volker Borchert) - 2017-07-28 18:19 +0000
    Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-07-28 13:28 -0700
      Re: What's the best way to make a cross string set? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-28 17:20 -0400
        Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-07-31 05:24 -0700
          Re: What's the best way to make a cross string set? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-31 12:01 -0400
            Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-07-31 10:58 -0700
          Re: What's the best way to make a cross string set? Sebastian <nowhere@nirvana.org> - 2017-07-31 18:13 +0200
          Re: What's the best way to make a cross string set? lewbloch@gmail.com - 2017-07-31 09:24 -0700
          Re: What's the best way to make a cross string set? Arne Vajhøj <arne@vajhoej.dk> - 2017-07-31 19:24 -0400
        Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-01 06:36 -0700
          Re: What's the best way to make a cross string set? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-08-01 10:58 -0400
            Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-01 08:09 -0700
              Re: What's the best way to make a cross string set? lewbloch@gmail.com - 2017-08-01 09:39 -0700
                Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-01 10:18 -0700
                Re: What's the best way to make a cross string set? Andreas Leitgeb <avl@logic.at> - 2017-08-02 09:22 +0000
                Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-02 05:13 -0700
                Re: What's the best way to make a cross string set? Andreas Leitgeb <avl@logic.at> - 2017-08-03 14:33 +0000
                Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-03 08:51 -0700
                Re: What's the best way to make a cross string set? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-08-03 12:20 -0400
                Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-03 10:15 -0700
                Re: What's the best way to make a cross string set? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-08-03 13:42 -0400
                Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-03 11:17 -0700
                Re: What's the best way to make a cross string set? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-08-05 16:08 -0400
                Re: What's the best way to make a cross string set? Martin Gregorie <martin@address-in-sig.invalid> - 2017-08-05 20:31 +0000
                Re: What's the best way to make a cross string set? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-08-05 17:25 -0400
                Re: What's the best way to make a cross string set? Martin Gregorie <martin@address-in-sig.invalid> - 2017-08-05 22:11 +0000
                Re: What's the best way to make a cross string set? Sebastian <nowhere@nirvana.org> - 2017-08-06 18:13 +0200
                Re: What's the best way to make a cross string set? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-02 12:56 -0700
  Re: What's the best way to make a cross string set? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-29 16:55 -0400
  Re: What's the best way to make a cross string set? Sebastian <nowhere@nirvana.org> - 2017-07-29 23:56 +0200

csiph-web