private void Run1InN(SingleNumber singleNumber) { int n = 4; int[] numbers = GetNumbers(1, n, 6); int single = singleNumber.Find1InNWithBitCount(numbers, n); Console.WriteLine($"BitCount: Single 1 in {n} of {string.Join(",", numbers)} is {single}"); n = 5; numbers = GetNumbers(1, n, 6); single = singleNumber.Find1InNWithBitCount(numbers, n); Console.WriteLine($"BitCount: Single 1 in {n} of {string.Join(",", numbers)} is {single}"); n = 3; numbers = GetNumbers(1, n, 2); single = singleNumber.Find1In3WithXor(numbers); Console.WriteLine($"Xor: Single 1 in {n} of {string.Join(",", numbers)} is {single}"); n = 3; numbers = GetNumbers(1, n, 3); single = singleNumber.Find1InNWithXor(numbers, n); Console.WriteLine($"XOR: Single 1 in {n} of {string.Join(",", numbers)} is {single}"); single = singleNumber.Find1InNWithXorOfComplex(numbers, n); Console.WriteLine($"XOR(Complex): Single 1 in {n} of {string.Join(",", numbers)} is {single}"); numbers = new int[] { 7, 7, 7, 1 }; single = singleNumber.Find1In3WithXor1(numbers); Console.WriteLine($"XOR1: Single 1 in 3 of {string.Join(",", numbers)} is {single}"); numbers = new int[] { 7, 7, 7, 7, 1 }; single = singleNumber.Find1In4WithXor1(numbers); Console.WriteLine($"XOR1: Single 1 in 4 of {string.Join(",", numbers)} is {single}"); }
public void Run() { SingleNumber singleNumber = new SingleNumber(); // Run1In2(singleNumber); Run1InN(singleNumber); // Run2In2(singleNumber); }
private void Run2In2(SingleNumber singleNumber) { int[] numbers = GetNumbers(2, 2, 6); string numbersString = string.Join(",", numbers); int[] singles = singleNumber.Find2In2WithXor(numbers); string singlesString = string.Join(",", singles); Console.WriteLine($"XOR: Single 2 in 2 of {numbersString} is {singlesString}"); }
private void Run1In2(SingleNumber singleNumber) { int[] numbers = GetNumbers(1, 2, 6); string s = string.Join(",", numbers); int single = singleNumber.Find1In2WithXor(numbers); Console.WriteLine($"XOR: Single 1 in 2 of {s} is {single}"); single = singleNumber.Find1In2WithBitCount(numbers); Console.WriteLine($"BitCount: Single 1 in 2 of {s} is {single}"); }