示例#1
0
        public static List <List <T> > Permute <T>(this List <T> toBePermuted)
        {
            var permutation = new List <List <T> >();
            int index       = 0;
            var totalOrder  = new Dictionary <int, T>();

            foreach (T item in toBePermuted)
            {
                totalOrder[index++] = item;
            }
            if (toBePermuted.Count() >= 13)
            {
                Console.WriteLine("List to big to Permute");
                return(null);
            }
            var max        = new Factoradic(FactorialTable.Get(toBePermuted.Count()));
            var lehmerCode = new Factoradic(0);
            int count      = 0;

            while (lehmerCode < max)
            {
                permutation.Add(DecodeLehmer(lehmerCode, totalOrder));
                count++;
                lehmerCode++;
            }
            return(permutation);
        }
示例#2
0
        public static Factoradic operator ++(Factoradic a)
        {
            int aTen          = a.ToBaseTen();
            var sumFactoradic = new Factoradic(aTen + 1);

            return(sumFactoradic);
        }
示例#3
0
        public static Factoradic operator -(Factoradic a, Factoradic b)
        {
            int aTen           = a.ToBaseTen();
            int bTen           = b.ToBaseTen();
            int difference     = aTen - bTen;
            var diffFactoradic = new Factoradic(difference);

            return(diffFactoradic);
        }
示例#4
0
        public static Factoradic operator *(Factoradic a, Factoradic b)
        {
            int aTen              = a.ToBaseTen();
            int bTen              = b.ToBaseTen();
            int product           = aTen * bTen;
            var productFactoradic = new Factoradic(product);

            return(productFactoradic);
        }
示例#5
0
        public static Factoradic operator +(Factoradic a, Factoradic b)
        {
            int aTen          = a.ToBaseTen();
            int bTen          = b.ToBaseTen();
            int sum           = aTen + bTen;
            var sumFactoradic = new Factoradic(sum);

            return(sumFactoradic);
        }
示例#6
0
        public static Factoradic operator /(Factoradic a, Factoradic b)
        {
            int aTen           = a.ToBaseTen();
            int bTen           = b.ToBaseTen();
            int quotient       = aTen / bTen;
            var quotFactoradic = new Factoradic(quotient);

            return(quotFactoradic);
        }
示例#7
0
        public override bool Equals(Object a)
        {
            Factoradic b = a as Factoradic;

            if (b == null)
            {
                return(false);
            }
            int  bTen = b.ToBaseTen();
            bool tF   = bTen == baseTen;

            return(tF);
        }
示例#8
0
        private static List <T> DecodeLehmer <T>(Factoradic lehmerCode, Dictionary <int, T> totalOrder)
        {
            var decoded  = new List <T>();
            int max      = totalOrder.Count;
            var dictCopy = new List <T>(totalOrder.Select(x => x.Value));

            for (int i = max - 1; i >= 0; i--)
            {
                int toBeAdded = lehmerCode.GetPlaceValue(i);
                T   item      = dictCopy[toBeAdded];
                decoded.Add(item);
                dictCopy.Remove(item);
            }
            return(decoded);
        }