Perfect Brick


Named after Leonhard Euler, is a cuboid whose edges and face diagonals all have integer lengths. A perfect cuboid (also called a perfect box) is an Euler brick whose space diagonal also has integer length. Up to now, it's an unsolved problem, if a perfect cuboid exists.

Try to find a box with size of a,b,c 
where a,b,c are integers and 
the diagonals d1,d2,d3,d4 are also integers
where d1=sqrt(a²+b²)
      d2=sqrt(a²+c²)
      d3=sqrt(b²+c²)
      d4=sqrt(a²+b²+c²)
and search with a <= b <= c <= maxInteger.
Code listing

public class PerfectBrick {

    static int maxSol = 1000;
    static int solCnt = 0;
    static long A[] = new long[maxSol];
    static long B[] = new long[maxSol];
    static long C[] = new long[maxSol];
    //--------------------------------------------------------------------------
    public static void solve(long a, long b, long c) {

        // try to ignore multiplied solutions
        for (int i = 0; i < solCnt; i++) {
            int n = (int) Math.floor(a / A[i]);

            if ((n * B[i]) == b && (n * C[i]) == c) {
                return;  //we already know this solution
            }
        }
        // try to remember
        A[solCnt] = a;
        B[solCnt] = b;
        C[solCnt] = c;
        solCnt++;
	long aa=a*a;
	long bb=b*b;
	long cc=c*c;
        long dd= aa + bb + cc;
        
        System.out.println(solCnt + "\t"+ a + "\t" + b + "\t" + c + 
                " \t\t" +(int) Math.sqrt(aa+bb)+
                "   \t" +(int) Math.sqrt(aa+cc)+
                "   \t" +(int) Math.sqrt(bb+cc)+
                "\t"+ Math.sqrt(dd));
       
	//System.out.flush();  
        //System.out.println("\t"+b/a+"\t"+c/a);
    }
    //--------------------------------------------------------------------------
    public static void info(int max) {
        System.out.println("Try to find a box with size of a,b,c ");
        System.out.println("where a,b,c are integers and ");
        System.out.println("the diagonals d1,d2,d3,d4 are also integers");
 
        System.out.println("where  a <= b <= c <= " + max + ".\n\n");
    }
    //--------------------------------------------------------------------------
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        int max = 10000;
        if (args.length>0) max=(int) new Integer(args[0]);
        info(max);
        long a, b, c, d, e, f;
        long a2, b2, c2;

        /* proof: 
         a² + b² = d²
         a² + c² = e²
         b² + c² = f²        
         */
        System.out.println("#\ta\tb\tc\t\td1\td2\td3\td4");
        for (a = 1; a < max; a++) {
            a2 = a * a;
            for (b = a; b < max; b++) {
                b2 = b * b;
                d = (int) Math.floor(Math.sqrt(a2 + b2));
                if ((a2 + b2) == (d * d)) {
                    for (c = b; c < max; c++) {
                        c2 = c * c;
                        e = (int) Math.floor(Math.sqrt(a2 + c2));
                        if ((a2 + c2) == (e * e)) {
                            f = (int) Math.floor(Math.sqrt(b2 + c2));
                            if ((b2 + c2) == (f * f)) {
                                solve(a, b, c);
                            }
                        }
                    }
                }
            }
        }
        System.out.println("done");
    }
}
as maxInteger on Zotac

Rolf LANG - Remsstr. 39 - 71384 Weinstadt | 07:24:33 up 29 days, 9:51, 1 user, load average: 0.13, 0.09, 0.09