// you’re reading...
1 Star2 Stars3 Stars4 Stars5 Stars (14 votes, average: 4.93 out of 5)
Loading...

Project Euler Solutions

Project Euler 75 Solution

Project Euler 75 Solution

Project Euler 75: Count the different lengths of wire that can form a right angle triangle in only one way


Project Euler 75 Problem Description

Project Euler 75: It turns out that 12 cm is the smallest length of wire that can be bent to form an integer sided right angle triangle in exactly one way, but there are many more examples.

12 cm: (3,4,5)
24 cm: (6,8,10)
30 cm: (5,12,13)
36 cm: (9,12,15)
40 cm: (8,15,17)
48 cm: (12,16,20)

In contrast, some lengths of wire, like 20 cm, cannot be bent to form an integer sided right angle triangle, and other lengths allow more than one solution to be found; for example, using 120 cm it is possible to form exactly three different integer sided right angle triangles.

120 cm: (30,40,50), (20,48,52), (24,45,51)

Given that L is the length of the wire, for how many values of L ≤ 1,500,000 can exactly one integer sided right angle triangle be formed?

Analysis

This is an extension to the Problem 9 solution.

Project Euler 75 Solution

Runs < 0.500 seconds in Python 2.7.

download arrowUse this link to get the Project Euler 75 Solution Python 2.7 source.

Afterthoughts

Project Euler 75 Solution last updated

Discussion

4 Responses to “Project Euler 75 Solution”

  1. It can be faster if you throw out the +i*i and -i*i from sum.

    Posted by W.Bruechle | September 15, 2015, 7:50 AM
    • The i*i is inside an abs() so you can’t just remove them. The abs() was used in place of an if so you could save a few ms by changing the sum line to:

      if j>i: sum = 2*j*(i+j)
      else: sum = 2*i*(i+j)

      or:
      sum = 2*(i+j)*max(i,j)

      Thanks for writing – this could yield a faster approach.

      Posted by Mike Molony | September 15, 2015, 8:25 PM
  2. Either the limit has changed on the euler page or you have used a wrong number.
    Nevertheless, the limit has to be 1500000(1,5 * 10^6)

    Posted by Klemens Nanni | January 28, 2010, 11:16 AM
    • Project Euler changes the limits from time-to-time to make the problem more challenging or to discourage ‘cheating.’ They do publish a notice at the bottom of each affected problem description to warn of changes.

      Note: This problem has been changed recently, please check that you are using the right parameters.

      I updated the program listing to include the new limit.

      Posted by Mike | July 10, 2011, 1:45 AM

Post a comment