Esempio n. 1
0
        private void RunTest(Xor xor, int[] nums, int k, int m)
        {
            string res = "";

            int[] results = null;
            int   count   = 0;

            if (m == 2)
            {
                results = xor.EqualOf2(nums, k);
                count   = xor.CountEqualOf2(nums, k);
                // count = xor.CountEqual2_Worst(nums, k);
            }
            else if (m == 3)
            {
                results = xor.EqualOf3(nums, k);
                count   = xor.CountEqualOf3(nums, k);
            }
            if (results != null)
            {
                res = string.Join(",", results);
            }
            else
            {
                res = "none";
            }
            Console.WriteLine($"The {m} number of {string.Join(",", nums)}, whose xor equal to {k} is {res} and the count is {count}");
        }
Esempio n. 2
0
        public void Run()
        {
            Xor xor = new Xor();

            RunTest(xor, new int[] { 3, 4, 5, 2, 4 }, 7, 2);
            RunTest(xor, new int[] { 1, 1, 1, 1 }, 0, 2);
            RunTest(xor, new int[] { 1, 2, 4, 3, 4, 0 }, 7, 3);
            RunTest(xor, new int[] { 1, 1, 1, 1 }, 1, 3);
            int[] nums;
            int   k;

            nums = GetNums(5);
            k    = 1;
            RunTest(xor, nums, k, 2);
            k = nums[0] ^ nums[1] ^ nums[2];
            RunTest(xor, nums, k, 3);
        }