import java.util.Arrays; import java.util.Scanner; public class Test { public static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int idx = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (i == j) continue; for (int k = 0; k < 4; k++) { if (i == k) continue; if (j == k) continue; for (int l = 0; l < 4; l++) { if (i == l) continue; if (j == l) continue; if (k == l) continue; p[idx][0] = i; p[idx][1] = j; p[idx][2] = k; p[idx][3] = l; idx++; } } } } chk(); } public static int[] b = new int[4]; public static int[] c = new int[4]; public static boolean[] t = new boolean[10]; public static int[][] p = new int[24][4]; public static void chk() { int hit, blw; for (b[0] = 0; b[0] < 7; b[0]++) { for (b[1] = b[0] + 1; b[1] < 8; b[1]++) { for (b[2] = b[1] + 1; b[2] < 9; b[2]++) { for (b[3] = b[2] + 1; b[3] < 10; b[3]++) { System.out.println("" + b[0] + b[1] + b[2] + b[3]); hit = sc.nextInt(); blw = sc.nextInt(); if (hit == 4) { return; } else if (hit + blw == 4) { chk4(); return; } else if (hit + blw == 3) { Arrays.fill(t, false); chk3(); return; } else if (hit + blw == 0) { Arrays.fill(t, false); chk0(); return; } } } } } } public static void chk0() { int hit, blw; for (int i = 0; i < 4; i++) { c[i] = b[i]; t[b[i]] = true; } for (b[0] = c[0] + 1; b[0] < 7; b[0]++) { if (t[b[0]]) continue; for (b[1] = b[0] + 1; b[1] < 8; b[1]++) { if (t[b[1]]) continue; for (b[2] = b[1] + 1; b[2] < 9; b[2]++) { if (t[b[2]]) continue; for (b[3] = b[2] + 1; b[3] < 10; b[3]++) { if (t[b[3]]) continue; System.out.println("" + b[0] + b[1] + b[2] + b[3]); hit = sc.nextInt(); blw = sc.nextInt(); if (hit == 4) { return; } else if (hit + blw == 4) { chk4(); return; } else if (hit + blw == 3) { chk3(); return; } } } } } } public static void chk3() { int hit, blw; for (int i = 0; i < 4; i++) { c[i] = b[i]; t[c[i]] = true; } for (int i = 0; i < 4; i++) { for (int j = c[i] + 1; j < 10; j++) { if (t[j]) continue; b[i] = j; System.out.println("" + b[0] + b[1] + b[2] + b[3]); hit = sc.nextInt(); blw = sc.nextInt(); if (hit == 4) { return; } else if (hit + blw == 4) { chk4(); return; } else if (hit + blw == 2) { break; } } b[i] = c[i]; } } public static void chk4() { int hit, blw; for (int i = 0; i < 4; i++) { c[i] = b[i]; } for (int i = 1; i < 24; i++) { for (int j = 0; j < 4; j++) { b[j] = c[p[i][j]]; } System.out.println("" + b[0] + b[1] + b[2] + b[3]); hit = sc.nextInt(); blw = sc.nextInt(); if (hit == 4) { return; } } } }