Java Source Code


// Author: Hannes du Plooy
// Date: 8 October 2013
// Objective: To solve the following
//  ONE
//  ONE
//  ONE
// +ONE
// ----
//  TEN

public class Puzzle001 {
    public static void main(String[] args) {
	    int O,E,N,T,E2;
	    int carry,tmp;
            String Os,Es,Ns,Ts;

	    for(O=1;O<10;O++) {
		    for(E=0;E<10;E++) {
		        if (O != E) {
		            tmp = E*4;
		            carry = tmp/10;
		            N = tmp % 10;
		            if (N == O || N == E)
		                continue;
		            tmp = carry + N*4;
		            carry = tmp/10;
		            E2 = tmp % 10;
		            if (E2 != E)
		                continue;
		            T = carry + O*4;
		            if (T >= 10)
		                continue;
		            if (T == O || T == E || T == N)
		                continue;
                    Os = Integer.toString(O);
                    Es = Integer.toString(E);
                    Ns = Integer.toString(N);
                    Ts = Integer.toString(T);
		            System.out.println("Answer is \n");
		            System.out.println(" "+Os+Ns+Es);
		            System.out.println(" "+Os+Ns+Es);
		            System.out.println(" "+Os+Ns+Es);
		            System.out.println(" "+Os+Ns+Es);
		            System.out.println("----");
		            System.out.println(" " +Ts+Es+Ns);
		            return;
		        }
		    }
	    }
    }
}