Guest User

Untitled

a guest
Jan 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1.   public List<List<char>> Results(List<char> allValues)
  2.         {
  3.             var collection = new List<List<char>>();
  4.             for (int counter = 0; counter < (1 << allValues.Count); ++counter)
  5.             {
  6.                 List<char> combination = new List<char>();
  7.                 for (int i = 0; i < allValues.Count; ++i)
  8.                 {
  9.                     if ((counter & (1 << i)) == 0)
  10.                         combination.Add(allValues[i]);
  11.                 }
  12.  
  13.                 // do something with combination
  14.                 collection.Add(combination);
  15.             }
  16.             return collection;
  17.         }
  18.  
  19.         void PowerSetofChars()
  20.         {
  21.             var chars = new List<char> { 'A', 'B', 'C' };
  22.  
  23.             var result = Results(chars);
  24.  
  25.         }
Add Comment
Please, Sign In to add comment