public class FindMissingNumber {

//	private static final long NUM_SIZE = 4_000_000_000L; // Long.MAX_VALUE = 9_223_372_036_854_775_807
	private static final long NUM_SIZE = 40;
	private static final int PORT_COUNT = 4; // Integer.MAX_VALUE = 2_147_483_647
	private static final int PORT_SIZE = (int) (NUM_SIZE / PORT_COUNT);

	public static void main(String[] args) {

		boolean[][] port = new boolean[PORT_COUNT][PORT_SIZE]; // req mem size = PORT_COUNT * PORT_SIZE bit

		for (long l = 0; l < NUM_SIZE; l++) {
			long n = readNumber();
			System.out.println("read = " + n);
			int i = (int) (n / PORT_SIZE);
			int j = (int) (n - (long) (i * PORT_SIZE));
			port[i][j] = true;
		}

		boolean found = false;
		for (int i = 0; i < PORT_COUNT; i++) {
			for (int j = 0; j < PORT_SIZE; j++) {
				if (!port[i][j]) {
					long n = (long) i * (long) PORT_SIZE + (long) j;
					System.out.println("!!!! FOUND !!!!! ==> " + n);
					found = true;
					break;
				}
			}
			if (found) {
				break;
			}
		}
	}

	private static long readNumber() {
		return (long) (Math.random() * NUM_SIZE);
	}

}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2016-09-22 14:04:02
Processing time 0.0048 sec