Results 1 to 3 of 3
  1. #1
    Junior Member
    TeKnOfY is offline

    Posts
    21

    Need help with a program (:

    Hi there, I need help with a program, it's pretty simple.

    It's to guess a four digit code. Every time you submit a guess, you are told how many numbers are correct, but not which numbers are.

    So basically a brute force bot that takes correct guesses into account to narrow down the 10,000 combinations.

    I would really appreciate anyone's help on this! I have no idea what language even would be best

  2. #2
    SF Pleb
    jak8222 is offline

    Posts
    141
    I sent you a message

  3. #3
    Senior Member
    Papaoutai is offline

    Posts
    222
    Code:
        public static void main(String[] args) {
            // TODO code application logic here
            
            String password = "1234";
            // Turn password into character array
            
            char[] passwordArray = String.valueOf(password).toCharArray();
            
            while(true) {
                
            // Get input
            Scanner in = new Scanner(System.in);
            String input = in.nextLine();
            
            // Turn input into character array
                
            char[] guessArray = String.valueOf(input).toCharArray();
            
            // Are both arrays equal?
            
            boolean isCorrect = Arrays.equals(passwordArray, guessArray);
            
            int counter = 0;
            
            // For 0 > 4, if password[1] == guess[1], increase counter
            
            for(int i = 0; i < 4; i++){
                if (passwordArray[i] == guessArray[i]) {
                    counter++;    
                }
            }
            
            // Print output
            
            System.out.println("Guess correct: " + isCorrect);
            System.out.println("Numbers correct: " + counter);
            
            
            }
        }
    This takes like 5 minutes to do with some basic programming knowledge, the logic of the program is explained in the comments

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •