var _array = new int[] { -4, -2, -1, 1, 2, 4 };
var keepPerms = new List<List<int>>();
var _l = new List<int>();
var c = 0;
while (c != 2)
{
for (int i = 0;i < _array.Length; i++)
{
_l.Add(_array[i]);
List<int> _sort = _l.OrderBy(s => s).ToList();
if (!keepPerms.Contains(_sort))
keepPerms.Add(_sort);
}
_l.Clear();
c++;
}
foreach (var item in keepPerms)
{
{
Console.WriteLine(String.Join(" ", item));
}
Console.WriteLine();
}
Console.WriteLine();
Output i get:
-4
-4 -2
-4 -2 -1
-4 -2 -1 1
-4 -2 -1 1 2
-4 -2 -1 1 2 4
-4
-4 -2
-4 -2 -1
-4 -2 -1 1
-4 -2 -1 1 2
-4 -2 -1 1 2 4
Output i need:
-4
-4 -2
-4 -2 -1
-4 -2 -1 1
-4 -2 -1 1 2
-4 -2 -1 1 2 4
It's a prototype of method where i need to find subsets of some sequnce. The main problem is that after doing this method i get duplicates of subsets. Is there any way to get the original values of list, despite the number of times I called it? Can you advise better way to find thise originals values of list.