
{"id":16057,"date":"2014-11-17T13:07:03","date_gmt":"2014-11-17T13:07:03","guid":{"rendered":"http:\/\/www.beautifulwork.org\/?p=16057"},"modified":"2014-11-17T13:07:03","modified_gmt":"2014-11-17T13:07:03","slug":"how-to-write-a-program-to-solve-project-euler-problem-9","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2014\/11\/17\/how-to-write-a-program-to-solve-project-euler-problem-9\/","title":{"rendered":"How to write a program to solve project euler problem 9 ?"},"content":{"rendered":"<pre>\n# There exists exactly one Pythagorean triplet for which a + b + c = 1000.                                                    \n# Find the product abc.                                                                                                       \n# This program is copied from http:\/\/code.jasonbhill.com\/python\/project-euler-problem-9\/                                      \n\n\nimport time\n\ndef prod_triplet_w_sum(n):\n    for i in range(1,n,1):\n        for j in range(1,n-i,1):\n            k = n-i-j\n            if i**2+j**2==k**2:\n                return i*j*k\n    return 0\n\nstart = time.time()\nproduct = prod_triplet_w_sum(1000)\nelapsed = (time.time() - start)\n\nprint \"found %s in %s seconds\" % (product,elapsed)\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p># There exists exactly one Pythagorean triplet for which a + b + c = 1000. # Find the product abc. # This program is copied from http:\/\/code.jasonbhill.com\/python\/project-euler-problem-9\/ import time def prod_triplet_w_sum(n): for i in range(1,n,1): for j in range(1,n-i,1): k = n-i-j if i**2+j**2==k**2: return i*j*k return 0 start = time.time() product = prod_triplet_w_sum(1000) &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2014\/11\/17\/how-to-write-a-program-to-solve-project-euler-problem-9\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to write a program to solve project euler problem 9 ?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[734,1099],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/16057"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=16057"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/16057\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=16057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=16057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=16057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}