Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Solve the puzzle using java

You are going to familiarize yourself with Java and a popular Java development environment, Eclipse. You will create a simple program that solves an interesting little problem, and the problem is as follows.
Solve the puzzle TOO + TOO + TOO + TOO = GOOD, where each single character represents a single distinct digit (0-9). Brute force is fine.
The program must print the output as follows, where values enclosed in square brackets are actually the numbers of the first solution found:
Solution: T = [w], O = [x], G = [y], D = [z]

 

Answer:


public class Answer {

	public static void main(String[] args)
	{
		
		for(int T = 0; T <= 9; T++) {
			for(int O = 0; O <= 9; O++) {
				for(int G = 0; G <= 9; G++) {
					for(int D = 0; D <= 9; D++) {

						// Ignore case of non-distinct digits
						if(T == O || T == G || T == D || O == G || O == D || G == D) {
							continue;
						}

						// One possible solution
						if(400*T == 1000*G + 66*O + D) {
							System.out.println("Solution: T = " + T
									                 + ", O = " + O
									                 + ", G = " + G
									                 + ", D = " + D);
						}
					}
				}
			}
		}
	}
}


About

Comment ( 1 )

  1. Hello! This is kind of off topic but I need some help
    from an established blog. Is it very hard to set up your own blog?
    I’m not very techincal but I can figure things out
    pretty fast. I’m thinking about making my own but I’m not sure where
    to begin. Do you have any ideas or suggestions?
    Cheers

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!