Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* The goal of this project is to,
- * Given a list of string (inputList),
- * Create a set of sets (masterList)
- * such that the masterList contains every possible set
- * that could be created from the input list.
- * This function is called by creating a list of string
- * and calling getAllSets, with input as a parameter.
- * Store the output if you like. If not, this currently prints everything out to console.
- * Have fun converting this to C#. Should be easy.
- */
- public static void main(String[] args)
- {
- List<String> input = Arrays.asList("a", "b", "c", "d", "e");
- getAllSets(input);
- }
- public static List<List<String>> getAllSets(List<String> input)
- {
- List<List<String>> masterSet = new ArrayList<List<String>>();
- int size = input.size();
- //end at math.pow(2,size)-1, because math.pow(2,size) will always be empty set
- for(int i = 0; i < Math.pow(2, size)-1; i++)
- {
- List<String> slaveSet = new ArrayList<String>();
- for(int j = 0; j < size; j++)
- {
- int x = (int)Math.pow(2, j+1);
- if(i%x < x/2)
- slaveSet.add(input.get(j));
- }
- masterSet.add(slaveSet);
- System.out.println("\t"+slaveSet);
- }
- return masterSet;
- }
- /* SAMPLE OUTPUT
- [a, b, c, d, e]
- [b, c, d, e]
- [a, c, d, e]
- [c, d, e]
- [a, b, d, e]
- [b, d, e]
- [a, d, e]
- [d, e]
- [a, b, c, e]
- [b, c, e]
- [a, c, e]
- [c, e]
- [a, b, e]
- [b, e]
- [a, e]
- [e]
- [a, b, c, d]
- [b, c, d]
- [a, c, d]
- [c, d]
- [a, b, d]
- [b, d]
- [a, d]
- [d]
- [a, b, c]
- [b, c]
- [a, c]
- [c]
- [a, b]
- [b]
- [a]
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement