{"id":552,"date":"2012-08-05T16:58:17","date_gmt":"2012-08-05T20:58:17","guid":{"rendered":"http:\/\/www.joshho.com\/blog\/?p=552"},"modified":"2012-09-07T16:11:20","modified_gmt":"2012-09-07T20:11:20","slug":"project-euler-problem-39","status":"publish","type":"post","link":"https:\/\/www.joshho.com\/blog\/2012\/08\/05\/project-euler-problem-39\/","title":{"rendered":"Project Euler &#8211; Problem 39"},"content":{"rendered":"<p>Problem 39: If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.<\/p>\n<p><center><\/p>\n<pre>{20,48,52}, {24,45,51}, {30,40,50}<\/pre>\n<p><\/center><\/p>\n<p>For which value of p  1000, is the number of solutions maximised?<br \/>\n<!--more--><br \/>\n<code><\/p>\n<pre lang='java'>\r\nclass runner\r\n{\r\n\tpublic static void main (String[] args) throws java.lang.Exception\r\n\t{\r\n\t\tlong time = System.currentTimeMillis();\r\n \r\n\t\tint largest_p = 0, largest_counter = 0;\r\n\t\t\r\n\t\t\/\/3+4+5 = 12\r\n\t\tfor(int p=12; p<1000; p++){\r\n\t\t\tint counter = 0;\r\n\t\t\t\r\n\t\t\tfor(int a=3;a<p-7;a++){\r\n\t\t\t\tint aa = a*a;\r\n\t\t\t\tfor(int b=a+1;b<p-a;b++){\r\n\t\t\t\t\tint bb = b*b;\r\n\t\t\t\t\tint absum = aa+bb;\r\n\t\t\t\t\tdouble c = Math.sqrt(absum);\r\n\t\t\t\t\tif(Math.floor(c) == c){\r\n\t\t\t\t\t\tif(a+b+c == p){\r\n\t\t\t\t\t\t\t\/\/System.out.println(p+\" \"+a+\" \"+b+\" \"+c);\r\n\t\t\t\t\t\t\tcounter++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif(largest_counter < counter){\r\n\t\t\t\tlargest_counter = counter;\r\n\t\t\t\tlargest_p = p;\r\n\t\t\t}\r\n\t\t}\r\n\t\tSystem.out.println(largest_p);\r\n\t\t\r\n\t\tSystem.out.println(\"time: \"+(System.currentTimeMillis() - time));\r\n\t}\r\n}\r\n<\/pre>\n<p><\/code><br \/>\nNote: Brute Force... better way is to generate the triples. [2sec]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem 39: If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.<\/p>\n<p><center><\/p>\n<pre>{20,48,52}, {24,45,51}, {30,40,50}<\/pre>\n<p><\/center><\/p>\n<p>For which value of p  1000, is the number of solutions maximised?<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[56],"tags":[],"_links":{"self":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts\/552"}],"collection":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/comments?post=552"}],"version-history":[{"count":0,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts\/552\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/media?parent=552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/categories?post=552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/tags?post=552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}