Exemplo n.º 1
0
        public static ModulusNumber F(BigInteger w, int h)
        {
            ModulusNumber result1 = Solve(w, h);
            ModulusNumber result2 = Solve(w, h - 1);

            return(result1 - result2);
        }
Exemplo n.º 2
0
        public ModulusNumber[] GetColumn(int index)
        {
            ModulusNumber[] column = new ModulusNumber[_rows];

            for (int i = 0; i < _rows; i++)
            {
                column[i] = _values[i, index];
            }

            return(column);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //ModulusNumber result1 = F(BigInteger.Pow(10, 12), 100);
            ModulusNumber result1 = new ModulusNumber(364553235);

            Console.WriteLine(result1);

            //ModulusNumber result2 = F(10000, 10000);
            ModulusNumber result2 = new ModulusNumber(749784357);

            Console.WriteLine(result2);

            //ModulusNumber result3 = F(100, BigInteger.Pow(10, 12));
            ModulusNumber result3 = new ModulusNumber(635147632);

            Console.WriteLine(result3);

            Console.WriteLine(result1 + result2 + result3);

            Console.Read();
        }
Exemplo n.º 4
0
 public ModulusEvenOdd(ModulusNumber even, ModulusNumber odd)
 {
     Even = even;
     Odd  = odd;
 }
Exemplo n.º 5
0
        private static ModulusNumber Solve(BigInteger w, int h)
        {
            int           size    = h * 2;
            ModulusMatrix matrix  = new ModulusMatrix(size, size);
            ModulusMatrix initial = new ModulusMatrix(size, 1);
            ModulusMatrix temp    = new ModulusMatrix(size, 1);

            // matrix loop
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    if (j == i)
                    {
                        initial[j, 0] = ModulusNumber.One;
                    }
                    else
                    {
                        initial[j, 0] = ModulusNumber.Zero;
                    }

                    temp[j, 0] = ModulusNumber.Zero;
                }

                // temp loop
                for (int j = 0; j < h; j++)
                {
                    ModulusEvenOdd total = new ModulusEvenOdd();

                    // initial loop
                    for (int k = 0; k < h; k++)
                    {
                        ModulusEvenOdd value = Get(initial, k);

                        if (k >= j)
                        {
                            total += value;
                        }
                        else
                        {
                            if (((j - k) % 2) == 1)
                            {
                                total += value.Swap;
                            }
                            else
                            {
                                total += value;
                            }
                        }
                    }

                    Set(temp, j, total);
                }

                matrix.SetColumn(i, temp.GetColumn(0));
            }

            for (int i = 0; i < h; i++)
            {
                if (i % 2 == 0)
                {
                    Set(initial, i, ModulusEvenOdd.OneEven);
                }
                else
                {
                    Set(initial, i, ModulusEvenOdd.OneOdd);
                }
            }

            ModulusMatrix powerMatrix = ModulusMatrix.Power(matrix, w - 1);
            ModulusMatrix result      = powerMatrix * initial;

            ModulusNumber sum = ModulusNumber.Zero;

            for (int i = 0; i < h; i++)
            {
                sum += result[i * 2 + 1, 0];
            }

            return(sum);
        }
Exemplo n.º 6
0
        private static ModulusNumber Solve(int w, int h)
        {
            ModulusEvenOdd[] previous = new ModulusEvenOdd[h];
            ModulusEvenOdd[] current  = new ModulusEvenOdd[h];

            for (int i = 0; i < h; i++)
            {
                if (i % 2 == 0)
                {
                    current[i] = ModulusEvenOdd.OneEven;
                }
                else
                {
                    current[i] = ModulusEvenOdd.OneOdd;
                }
            }

            for (int i = 1; i < w; i++)
            {
                Console.WriteLine(i);

                ModulusEvenOdd[] temp = previous;
                previous = current;
                current  = temp;

                for (int j = 0; j < h; j++)
                {
                    ModulusEvenOdd total = new ModulusEvenOdd();

                    for (int k = 0; k < h; k++)
                    {
                        ModulusEvenOdd value = previous[k];

                        if (k >= j)
                        {
                            total += value;
                        }
                        else
                        {
                            if (((j - k) % 2) == 1)
                            {
                                total += value.Swap;
                            }
                            else
                            {
                                total += value;
                            }
                        }
                    }

                    current[j] = total;
                }
            }

            ModulusNumber sum = ModulusNumber.Zero;

            for (int i = 0; i < h; i++)
            {
                sum += current[i].Odd;
            }

            return(sum);
        }