/// <summary>
        /// retreive a specific lexical premutation
        /// </summary>
        /// <param name="workingNumberToFind"></param>
        /// <returns></returns>
        public string GetPremutation(long numberToFind)
        {
            string result              = null;
            string startingSequence    = originalSequence;
            long   workingNumberToFind = numberToFind;

            for (long digit = 0; digit < originalSequence.Length - 1; digit++)
            {
                long factorial = MathLibrary.Factorial(originalSequence.Length - digit - 1);
                long position  = workingNumberToFind / factorial;
                long remainder = workingNumberToFind % factorial;

                if (remainder > 0)
                {
                    position++;
                }

                result           = result + startingSequence.Substring((int)position - 1, 1);
                startingSequence = startingSequence.Remove((int)position - 1, 1);

                long factorialBorder = (position - 1) * factorial;
                workingNumberToFind = workingNumberToFind - factorialBorder;
            }

            return(result + startingSequence);
        }
 /// <summary>
 /// Create premutations based on an array of digits
 /// </summary>
 /// <param name="things"></param>
 public Premutations(long[] things)
 {
     this.things      = things;
     count            = MathLibrary.Factorial(things.Length);
     originalSequence = null;
     foreach (long digit in things)
     {
         originalSequence = digit.ToString() + originalSequence;
     }
 }
 /// <summary>
 /// Create premutations based on a list of digits
 /// </summary>
 /// <param name="things"></param>
 public Premutations(List <long> things)
 {
     this.things      = things.ToArray <long>();
     count            = MathLibrary.Factorial(things.Count);
     originalSequence = null;
     foreach (long digit in things)
     {
         originalSequence = digit.ToString() + originalSequence;
     }
 }
示例#4
0
        /// <summary>
        /// This method returns a collection of factors for a given number
        /// </summary>
        /// <param name="number"></param>
        /// <param name="primeNumbers"></param>
        /// <returns></returns>
        public static List <long> GetDistinctFactors(long number, List <long> primeNumbers)
        {
            List <long> factors = MathLibrary.GetFactors(number, primeNumbers);

            return(factors.Distinct().ToList());
        }
示例#5
0
        /// <summary>
        /// This method returns a collection of factors for a given number
        /// This method is being deprecated!
        /// </summary>
        /// <param name="number">The number being factored</param>
        /// <returns>Collection of factors</returns>
        public static List <long> GetFactors(long number)
        {
            List <long> primeNumbers = MathLibrary.GetPrime(10000); // (number / 2);

            return(GetFactors(number, primeNumbers));
        }
 /// <summary>
 /// Create premutations base on a string of digits
 /// </summary>
 /// <param name="things"></param>
 public Premutations(string things)
 {
     this.originalSequence = things;
     count = MathLibrary.Factorial(things.Length);
 }