예제 #1
0
 //
 //places is the size of the array
 // fills is the number of recursions
 public static HashSet <dec> Permute(int places, int fills, HashSet <dec> set = null, int basis = 0)
 {
     if (set == null)
     {
         set = new HashSet <dec>();
     }
     //if places = 4 & fills = 1
     //1000 0100 0010 0001
     //if places = 3 & fills = 2
     //110 101 011
     for (int i = places - 1; i >= 0; i--)
     {
         if (((1 << i) | basis) == basis)
         {
             continue;
         }
         dec newVal = basis + (1 << i);
         if (fills == 1)
         {
             set.Add(newVal);
         }
         else
         {
             Permute(places - 1, fills - 1, set, newVal);
         }
     }
     return(set);
 }
예제 #2
0
        public static dec Add6And9(dec i)
        {
            dec six  = 0b0000100000;
            dec nine = 0b0100000000;

            if ((i | six) == i || (i | nine) == i)
            {
                i = i | six;
                i = i | nine;
            }
            return(i);
        }
예제 #3
0
        public static bool HasBoth(dec a, dec b)
        {
            dec[][] sqrs =
                squares.Select(e => e.Select(z => IntToDecPos(z)).ToArray()).ToArray();

            a = Add6And9(a);
            b = Add6And9(b);
            foreach (dec[] d in sqrs)
            {
                if ((a | d[0]) == a && (b | d[1]) == b)
                {
                    continue;
                }
                if ((b | d[0]) == b && (a | d[1]) == a)
                {
                    continue;
                }
                return(false);
            }
            return(true);
        }