Skip to content

Instantly share code, notes, and snippets.

@NDiiong
Created February 2, 2021 09:34
Show Gist options
  • Save NDiiong/1304b7430ea116b785ed8a149e014b19 to your computer and use it in GitHub Desktop.
Save NDiiong/1304b7430ea116b785ed8a149e014b19 to your computer and use it in GitHub Desktop.
Subset Algorithm
combine(new int[] { 1, 2, 3, 4, 5, 6 }, new List<int>(), 0);
static void combine(int[] a, List<int> outstr, int index)
{
for (int i = index; i < a.Length; i++)
{
int count = 0;
foreach (var item in outstr)
count += item;
if ((a[i] + count) == 10)
{
foreach (var item in outstr)
Console.Write("{0}", item);
Console.Write("{0}", a[i]);
Console.WriteLine();
}
outstr.Add(a[i]);
combine(a, outstr, i + 1);
outstr.Remove(a[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment