This program combines two functions into one unified tool:
-
🔎
maxXor: Find the maximum XOR value within a given range. -
🔢
minimumMoves: Calculate the minimum moves required to match two arrays digit by digit.
- ✅ maxXor: Calculates the largest XOR result for pairs
(a, b)wherelo ≤ a, b ≤ hiand ensures the result is within a given limitk. - ✅ minimumMoves: Compares two integer arrays and calculates the total "move count" to match them, where a "move" is incrementing or decrementing individual digits.
- ✅ Menu-Driven Interface: Easy-to-use interactive input selection for seamless operation.
Clone the repository and run the program:
git clone https://github.com/yourusername/xor-array-matcher.git
cd xor-array-matcher
python3 main.py
- Run the program. A menu will appear asking you to choose a function:
Select which function to run:
1. maxXor
2. minimumMoves
Enter your choice (1 or 2):
Input the range [lo, hi] and the maximum allowable XOR value k. The program will calculate the largest possible XOR value satisfying the conditions.
Input:
Running maxXor function...
Enter the lower bound (lo): 3
Enter the upper bound (hi): 5
Enter the maximum XOR value (k): 6
Output:
Maximum XOR value: 6
Explanation:
- Pairs
(3, 5)give XOR = 6, which is the largest value ≤ 6.
Input two arrays of integers. The program calculates the total number of moves needed to make both arrays identical.
- A move: Incrementing or decrementing a single digit in a number.
Input:
Running minimumMoves function...
Enter the number of elements in the first array: 2
Enter element 1 for array 1: 1234
Enter element 2 for array 1: 5678
Enter the number of elements in the second array: 2
Enter element 1 for array 2: 2345
Enter element 2 for array 2: 6789
Output:
Total minimum moves: 10
Explanation:
-
Compare
1234to2345:- Moves:
1→2, 2→3, 3→4, 4→5→ 4 moves.
- Moves:
-
Compare
5678to6789:- Moves:
5→6, 6→7, 7→8, 8→9→ 4 moves.
- Moves:
-
Total = 4 + 4 = 8 moves.