fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. static uint FromArray(int[] data) {
  8. uint res = 0;
  9. for (int i = 0 ; i != data.Length ; i++) {
  10. if (data[i] == 1) {
  11. res |= (1U << i);
  12. }
  13. }
  14. return res;
  15. }
  16. static int[] ToArray(uint set, int size) {
  17. var res = new int[size];
  18. for (int i = 0 ; i != size ; i++) {
  19. if ((set & (1U << i)) != 0) {
  20. res[i] = 1;
  21. }
  22. }
  23. return res;
  24. }
  25. static int CountBits(uint set) {
  26. int res = 0;
  27. while (set != 0) {
  28. if ((set & 1) != 0) {
  29. res++;
  30. }
  31. set >>= 1;
  32. }
  33. return res;
  34. }
  35. public static void Main()
  36. {
  37. var example = new[]{1, 1, 1, 0, 1, 1};
  38. var set = FromArray(example);
  39. int N = example.Length;
  40. var res = new List<uint>();
  41. for (uint mask = 0 ; mask != 1U<<N ; mask++) {
  42. var candidate = set & mask;
  43. if (CountBits(candidate) == 3) {
  44. res.Add(candidate);
  45. }
  46. }
  47. foreach (var s in res.Distinct()) {
  48. var array = ToArray(s, N);
  49. Console.WriteLine(string.Join(" ", array.Select(i => i.ToString()).ToArray()));
  50. }
  51. }
  52. }
Success #stdin #stdout 0.04s 34048KB
stdin
Standard input is empty
stdout
1 1 1 0 0 0
1 1 0 0 1 0
1 0 1 0 1 0
0 1 1 0 1 0
1 1 0 0 0 1
1 0 1 0 0 1
0 1 1 0 0 1
1 0 0 0 1 1
0 1 0 0 1 1
0 0 1 0 1 1