Tuesday, December 2, 2014

Special Pythagorean triplet problem

Another coding challenge from projecteuler.net


A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.





https://projecteuler.net/problem=9


outermost: for (double a = 1; a < 1000; a++) {
    double aProduct = Math.pow(a, 2);
    for (double b = 1; b < 1000; b++) {
        double bProduct = Math.pow(b, 2);
        double c = Math.sqrt(aProduct + bProduct);
        if (Math.floor(c) == c && a + b + c == 1000){
            System.out.println("Pythagorean triplet: a:" + a +  " b:" + b + " c:" + c);
            System.out.println("answer: " + (a * b * c));
            break outermost;
        }
    }
}


Fell off the blogging wagon

It is so easy to fall into a rut.  It takes effort to keep putting in that extra effort.  Just like going to the gym if you keep to a schedule you are fine but once you break that routine you often completely fall off the wagon.  That is what has happened to this blog and I need to get back on track.