예제 #1
0
 public WordCountCalculator(ITextSplitter textSplitter, IWordCounter wordCounter, IPrimeNumberChecker primeChecker)
 {
     this.textSplitter = textSplitter;
     this.wordCounter = wordCounter;
     this.primeChecker = primeChecker;
     
 }
예제 #2
0
        public static int Kronecker_Jacobi(int a, int b, IPrimeNumberChecker primeNumberChecker)
        {
            if (b == 0)
            {
                return(System.Math.Abs(a) == 1 ? 1 : 0);
            }

            // a and b are both even
            if (MathBase.IsEven(b) && MathBase.IsEven(a))
            {
                return(0);
            }

            int factor = 1;

            if (b < 0 && a >= 0)
            {
                b = -b;
            }
            else if (b < 0 && a < 0)
            {
                b      = -b;
                factor = -1;
            }

            if (b == 1)
            {
                return(factor);
            }

            if (b == 2)
            {
                if (MathBase.IsEven(a))
                {
                    return(0);
                }

                int aMod8 = a & 7;

                if ((aMod8 == 1) || aMod8 == 7)
                {
                    return(factor); // a = 1, -1 mod 8
                }
                return(-factor);    // a = 3, -3 mod 8
            }

            a %= b;

            // 0 <= a < b and 0 < b <= MaxInt
            if (a < 0)
            {
                a += b;
            }

            if (a == 0)
            {
                return(0);
            }

            if (a == 1)
            {
                return(factor);
            }

            int[] tab2 = { 0, 1, 0, -1, 0, -1, 0, 1 };

            // (-1)^((a^2-1)/8) == tab2[a & 7]
            int v = 0;

            while (MathBase.IsEven(b))
            {
                v++;
                b >>= 1;
            }

            int k;

            if (MathBase.IsEven(v))
            {
                k = 1;
            }
            else
            {
                k = tab2[a & 7];
            }

            //step3:
            do
            {
                if (a == 0)
                {
                    if (b > 1)
                    {
                        return(0);
                    }
                    else
                    {
                        return(k * factor);
                    }
                }

                v = 0;
                while (MathBase.IsEven(a))
                {
                    v++;
                    a >>= 1;
                }

                if (!MathBase.IsEven(v))
                {
                    k *= tab2[b & 7];       // k *= (-1)**((b*b-1)/8)
                }

                // step4:
                if ((a & b & 2) != 0)
                {
                    k = -k; // k = k*(-1)**((a-1)*(b-1)/4)
                }

                int r = a;
                a = b % r;
                b = r;
                // goto step3;
            }while (true);
        }
 public PrimeNumberGenerator(IPrimeNumberChecker primeNumberChecker)
 {
     _primeNumberChecker = primeNumberChecker;
 }
 public CheckIsPrimeNumberQueryHandler(IPrimeNumberChecker primeNumberChecker)
 {
     _primeNumberChecker = primeNumberChecker;
 }
예제 #5
0
 public WordCountCalculator()
 {
     textSplitter = new TextSplitter();
     wordCounter = new WordCounter();
     primeChecker = new PrimeNumberChecker();
 }
예제 #6
0
 public WordCountCalculator(ITextSplitter textSplitter, IWordCounter wordCounter, IPrimeNumberChecker primeChecker)
 {
     this.textSplitter = textSplitter;
     this.wordCounter  = wordCounter;
     this.primeChecker = primeChecker;
 }
예제 #7
0
 public WordCountCalculator()
 {
     textSplitter = new TextSplitter();
     wordCounter  = new WordCounter();
     primeChecker = new PrimeNumberChecker();
 }
 public GetNextIfNotPrimeOrCurrentQueryHandler(IPrimeNumberGenerator primeNumberGenerator, IPrimeNumberChecker primeNumberChecker)
 {
     _primeNumberGenerator = primeNumberGenerator;
     _primeNumberChecker   = primeNumberChecker;
 }