Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Guess Number
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { private static String target = "3536"; public static void main(String args[]) { System.out.println(guess()); } private static int guessServer(String guess) { System.out.println("GuessServer call: " + guess); int[] count = new int[6]; int res = 0; for (int i = 0; i < 4; i++) count[target.charAt(i) - '1']++; for (int i = 0; i < 4; i++) if (count[guess.charAt(i) - '1']-- > 0) res++; return res; } public static String guess() { StringBuilder sb = new StringBuilder(); for (int i = 1; i < 6 && sb.length() < 4; i++) { int len = sb.length(); while (sb.length() < 4) sb.append(i); int match = guessServer(sb.toString()); sb.setLength(match); } while (sb.length() < 4) sb.append(6); return sb.toString(); } }
run
|
edit
|
history
|
help
0
Construct Tree from Ancestor Matrix
Problem: on_off
1
Random and count of even numbers (ver. 2)
Java Array List
Implementation of several common methods of LinkedList
ElaineBrown**
MAP List Iterator
Java Variable
4a