コード例 #1
0
        public static int SolveEq(int[] coefs, bool verbose = false)
        {
            if (coefs.Length != 9)
            {
                throw new ArgumentException("Input array shold be 9 elements long");
            }

            int[,] binaryCoefs = new int[8, 9];

            if (verbose)
            {
                Console.WriteLine("");
            }

            for (int i = 0; i <= 8; i++)
            {
                int[] binary = ConvertToBinary(coefs[i]);

                if (verbose)
                {
                    Console.Write(coefs[i] + "_10 = ");

                    for (int j = 7 - binary.Length + 1; j < 8; j++)
                    {
                        Console.Write(binary[7 - j]);
                    }

                    Console.WriteLine("_2");
                }

                for (int j = 0; j < binary.Length; j++)
                {
                    binaryCoefs[7 - j, i] = binary[j];
                }
            }

            var matrix = new AndXorSystem(binaryCoefs);

            try {
                return(matrix.Solve(verbose));
            }
            catch (SystemNonConsistentException) {
                return(-1);
            }
        }
コード例 #2
0
        public static int SolveEq(int[] coefs, bool verbose = false)
        {
            if(coefs.Length != 9)
                throw new ArgumentException("Input array shold be 9 elements long");

            int[,] binaryCoefs = new int[8, 9];

            if(verbose)
                Console.WriteLine("");

            for(int i = 0; i <= 8; i++) {
                int[] binary = ConvertToBinary(coefs[i]);

                if(verbose) {
                    Console.Write(coefs[i] + "_10 = ");

                    for(int j = 7 - binary.Length + 1; j < 8; j++)
                        Console.Write(binary[7 - j]);

                    Console.WriteLine("_2");
                }

                for(int j = 0; j < binary.Length; j++) {
                    binaryCoefs[7 - j, i] = binary[j];
                }
            }

            var matrix = new AndXorSystem(binaryCoefs);

            try {
                return matrix.Solve(verbose);
            }
            catch(SystemNonConsistentException) {
                return -1;
            }
        }