Project Euler – Problem 9 Solution (Java)

http://projecteuler.net/index.php?section=problems&id=9

	/* Project Euler - Problem 9 (http://projecteuler.net/index.php?section=problems&id=9)
	 *
	 * Pretty simple brute force method.
	 */
	public static void p9(){
		double a = 0, b = 0, c = 0;

		for(a=0; a<1000; a++){
			for(b=a+1; b<1000; b++){
				c = Math.sqrt(Math.pow(a, 2) + Math.pow(b,2));
				if(b<c && a+b+c == 1000) break;
			}
			if(b<c && a+b+c == 1000) break;
		}

		System.out.println((int)(a*b*c));
	}

Note: After writing this I saw a mathematical solution on the forum. It utilizes stuff I vaguely remember so I’ll have to refresh my Geometry skills and redo this one soon :o )

No Comments »

Tina on January 30th 2009 in Project Euler

Trackback URI | Comments RSS

Leave a Reply