(int n, int missing)
| 6 | public class Question { |
| 7 | /* Create a random array of numbers from 0 to n, but skip 'missing' */ |
| 8 | public static ArrayList<BitInteger> initialize(int n, int missing) { |
| 9 | BitInteger.INTEGER_SIZE = Integer.toBinaryString(n).length(); |
| 10 | ArrayList<BitInteger> array = new ArrayList<BitInteger>(); |
| 11 | |
| 12 | for (int i = 1; i <= n; i++) { |
| 13 | array.add(new BitInteger(i == missing ? 0 : i)); |
| 14 | } |
| 15 | |
| 16 | // Shuffle the array once. |
| 17 | for (int i = 0; i < n; i++){ |
| 18 | int rand = i + (int) (Math.random() * (n-i)); |
| 19 | array.get(i).swapValues(array.get(rand)); |
| 20 | } |
| 21 | |
| 22 | return array; |
| 23 | } |
| 24 | |
| 25 | |
| 26 | public static int findMissing(ArrayList<BitInteger> array) { |
no test coverage detected