using System.Collections.Generic;
public static class Extensions
public static uint Sum(this IEnumerable<uint> source)
return source.Aggregate(sum, (current, v) => current + v);
public static IEnumerable<T[]> GetCombinations<T>(T[] source)
for (var i = 0; i < (1 << source.Length); i++)
yield return source.Where((t, j) => (i & (1 << j)) != 0).ToArray();
public static IEnumerable<uint[]> GetItems(IEnumerable<uint> source, uint target) => GetCombinations(source.ToArray()).Where(items => items.Sum() == target);
static void Main(string[] args)
uint[] values = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, };
foreach (var found in GetItems(values, 96))
Console.WriteLine(string.Join(", ", found));