示例#1
0
        public static void BruteForceCreateCnWithLimit(UInt32 n, UInt32 limit, ISimpleList <UInt32> Cn, ISimpleList <UInt32> GnBuffer)
        {
            if (n == 0)
            {
                throw new ArgumentOutOfRangeException("n", n, "n cannot be 0");
            }

            Cn.Add(1);

            for (UInt32 potentialCoprime = 2; potentialCoprime <= limit; potentialCoprime++)
            {
                Boolean isCoprime = true;
                for (UInt32 primeIndex = 0; primeIndex < n; primeIndex++)
                {
                    UInt32 prime = PrimeTable.Values[primeIndex];
                    if ((potentialCoprime % prime) == 0)
                    {
                        isCoprime = false;

                        if (primeIndex == n - 1)
                        {
                            GnBuffer.Add(potentialCoprime);
                        }
                        break;
                    }
                }

                if (isCoprime)
                {
                    Cn.Add(potentialCoprime);
                }
            }
        }
示例#2
0
        public void AliasesAndProperties()
        {
            ISimpleList list = GoInterface <ISimpleList> .From(new MyCollection(), CastOptions.AllowUnmatchedMethods);

            list.Add(10);
            Assert.That(list[0].Equals(10));
            Assert.AreEqual(1, list.Count);
        }
        public static void MergeSort(this ISimpleList <int> list)
        {
            var result = SplitAndMerge(list, 0, list.Count - 1);

            list.Clear();
            foreach (var value in result)
            {
                list.Add(value);
            }
        }
        public static void HeapSort(this ISimpleList <int> list)
        {
            var heap = new SimpleHeap <int>();

            foreach (var value in list)
            {
                heap.Insert(value);
            }
            list.Clear();
            while (heap.Count > 0)
            {
                list.Add(heap.RemoveTop());
            }
        }
示例#5
0
        public string[] Run(ISimpleList <String> array, string[] input)
        {
            var instructions = input;

            foreach (var instruction in instructions)
            {
                char   command = instruction[0];
                String value   = instruction.Substring(1);
                switch (command)
                {
                case '+':
                    array.Add(value);
                    break;

                case '-':
                    array.RemoveAt(Int32.Parse(value));
                    break;

                case '~':
                    array.Clear();
                    break;

                case '^':
                    var    t     = value.Split(' ');
                    int    index = Int32.Parse(t[0]);
                    String item  = t[1];
                    array.Insert(index, item);
                    break;

                default:
                    break;
                }
            }
            int lenght = array.Count;
            var result = new String[lenght];

            for (int i = 0; i < lenght; i++)
            {
                result[i] = array[i];
            }
            return(result);
        }
示例#6
0
        public static UInt32[] BruteForceCreateCn(UInt32 n, UInt32 count, ISimpleList <UInt32> GnBuffer)
        {
            if (n == 0)
            {
                throw new ArgumentOutOfRangeException("n", n, "n cannot be 0");
            }

            UInt32[] Cn = new UInt32[count];
            Cn[0] = 1;
            UInt32 nextCnIndex = 1;

            for (UInt32 potentialCoprime = 2; nextCnIndex < count; potentialCoprime++)
            {
                Boolean isCoprime = true;
                for (UInt32 primeIndex = 0; primeIndex < n; primeIndex++)
                {
                    UInt32 prime = PrimeTable.Values[primeIndex];
                    if ((potentialCoprime % prime) == 0)
                    {
                        isCoprime = false;

                        if (primeIndex == n - 1)
                        {
                            GnBuffer.Add(potentialCoprime);
                        }

                        break;
                    }
                }

                if (isCoprime)
                {
                    Cn[nextCnIndex++] = potentialCoprime;
                }
            }

            return(Cn);
        }