12732 - Guess the Fake Coin

The forum to report every bug you find or tell us what you'd like to find in UVa OJ

Moderator: Board moderators

Post Reply
lhrios
New poster
Posts: 1
Joined: Sun Jan 22, 2017 1:28 pm

12732 - Guess the Fake Coin

Post by lhrios » Sun Jan 22, 2017 1:43 pm

It seems that there is something wrong with the judge. The last accepted submission was almost two years ago. I have developed a simple judge for this problem and my code works fine with it. Therefore, I would like to ask some that already got an accepted code to resubmit in order to test the judge.

Code: Select all

package p12732;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import java.util.Scanner;

public class Executor {
	private static final int NUMBER_OF_TESTS = 10000;
	private static final String EXECUTABLE = "/data/home/luis/uva problem set/12732/a.out";

	public static void main(String[] args) throws IOException {
		long seed = System.nanoTime();
		System.out.printf("The random seed is %d\n", seed);
		Random random = new Random(seed);

		final Process process = new ProcessBuilder(EXECUTABLE).start();
		Scanner scanner = new Scanner(process.getInputStream());
		PrintWriter printWriter = new PrintWriter(process.getOutputStream());
		printWriter.println(NUMBER_OF_TESTS);
		printWriter.flush();

		for (int i = 0; i < NUMBER_OF_TESTS; i++) {
			int n = 3 + (Math.abs(random.nextInt()) % (120 + 1 - 3));
			n = 120;
			int answer = (Math.abs(random.nextInt()) % n) + 1;

			// n = 9;
			// answer = 6;

			System.out.printf("n is %d\n", n);
			System.out.printf("The answer is %d\n", answer);

			printWriter.println(n);
			printWriter.flush();

			while (true) {
				String command = scanner.next();
				System.err.println(command);
				if ("Answer".equals(command)) {
					int returnedAnswer = scanner.nextInt();
					System.err.println(returnedAnswer);
					if (answer != returnedAnswer) {
						System.out.printf("Expecting %d but found %d\n", answer, returnedAnswer);
						System.exit(1);
					}
					break;

				} else if ("Test".equals(command)) {
					String coins = scanner.nextLine();
					Scanner coinsScanner = new Scanner(coins);
					int coinCount = 0;
					int especialCoinIndex = -1;
					while (true) {
						if (!coinsScanner.hasNext()) {
							System.err.println();
							assert (coinCount % 2 == 0);
							if (especialCoinIndex == -1) {
								System.err.println("0");
								printWriter.println("0");

							} else if (especialCoinIndex >= coinCount / 2) {
								System.err.println("-1");
								printWriter.println("-1");

							} else {
								System.err.println("1");
								printWriter.println("1");
							}
							printWriter.flush();
							break;

						} else {
							int coin = coinsScanner.nextInt();
							System.err.print(" ");
							System.err.print(coin);
							if (coin == answer) {
								assert (especialCoinIndex == -1);
								especialCoinIndex = coinCount;
							}
							coinCount++;
						}
					}

				} else {
					assert false;
				}
			}
		}
	}
}

Post Reply

Return to “Bugs and suggestions”