fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. static int[] d;
  8. public static void Main()
  9. {
  10. d = (new int[] {1,3,4,2,6,7,5,5,8,10,9,10,7,17}).OrderBy(x => x).ToArray();
  11. var query = foo(new int[]{}, 0).Select(item => string.Join(",", item)).Distinct();
  12. foreach (var item in query)
  13. Console.WriteLine(item);
  14. Console.WriteLine(query.Count());
  15. }
  16. static IEnumerable<IEnumerable<int>> foo(IEnumerable<int> seed, int n)
  17. {
  18. if (seed.Sum() == 29)
  19. {
  20. yield return seed;
  21. }
  22. else
  23. {
  24. if (seed.Sum() < 29)
  25. {
  26. for (int i = n; i < d.Count(); i++)
  27. {
  28. var items = foo(seed.Concat(d.Skip(i).Take(1)), i + 1);
  29. foreach (var item in items) yield return item;
  30. }
  31. }
  32. }
  33. }
  34.  
  35. }
Success #stdin #stdout 0.18s 24328KB
stdin
Standard input is empty
stdout
1,2,3,4,5,5,9
1,2,3,4,5,6,8
1,2,3,4,5,7,7
1,2,3,4,9,10
1,2,3,5,5,6,7
1,2,3,5,8,10
1,2,3,6,7,10
1,2,3,6,8,9
1,2,3,6,17
1,2,3,7,7,9
1,2,4,5,7,10
1,2,4,5,8,9
1,2,4,5,17
1,2,4,6,7,9
1,2,4,7,7,8
1,2,5,5,6,10
1,2,5,5,7,9
1,2,5,6,7,8
1,2,6,10,10
1,2,7,9,10
1,2,9,17
1,3,4,5,6,10
1,3,4,5,7,9
1,3,4,6,7,8
1,3,5,5,6,9
1,3,5,5,7,8
1,3,5,6,7,7
1,3,5,10,10
1,3,6,9,10
1,3,7,8,10
1,3,8,17
1,4,5,5,6,8
1,4,5,5,7,7
1,4,5,9,10
1,4,6,8,10
1,4,7,7,10
1,4,7,8,9
1,4,7,17
1,5,5,8,10
1,5,6,7,10
1,5,6,8,9
1,5,6,17
1,5,7,7,9
1,6,7,7,8
1,8,10,10
2,3,4,5,5,10
2,3,4,5,6,9
2,3,4,5,7,8
2,3,4,6,7,7
2,3,4,10,10
2,3,5,5,6,8
2,3,5,5,7,7
2,3,5,9,10
2,3,6,8,10
2,3,7,7,10
2,3,7,8,9
2,3,7,17
2,4,5,5,6,7
2,4,5,8,10
2,4,6,7,10
2,4,6,8,9
2,4,6,17
2,4,7,7,9
2,5,5,7,10
2,5,5,8,9
2,5,5,17
2,5,6,7,9
2,5,7,7,8
2,7,10,10
2,8,9,10
2,10,17
3,4,5,7,10
3,4,5,8,9
3,4,5,17
3,4,6,7,9
3,4,7,7,8
3,5,5,6,10
3,5,5,7,9
3,5,6,7,8
3,6,10,10
3,7,9,10
3,9,17
4,5,5,6,9
4,5,5,7,8
4,5,6,7,7
4,5,10,10
4,6,9,10
4,7,8,10
4,8,17
5,5,9,10
5,6,8,10
5,7,7,10
5,7,8,9
5,7,17
6,7,7,9
9,10,10
96