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);
}
}
}
}
}
}
}
Comment ( 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