Charlie Harvey

#870

I learned a lot following along with your discussion and code. I know it's been a few years since you wrote this blog entry, but wanted to add some comments to correctly guide other readers.

Your isInt function should be changed, one suggestion: isInt x = abs (x - (fromIntegral $ round x)) < 0.000001

Ceiling will always round UP, so for example ceiling 1.01 gives 2. The abs function ensures that things work whether the "nearly" integer value is slightly above or below its neighboring integer.

Regarding your Euclidean approach: it is incorrect that the method only produces primitives. For example m=3, n=1 produces (6,8,10). However, it is true that the triplets produced this way is a strict subset of all the triplets, and that the solution to the problem is NOT contained in this subset.

Final note: Floats can be avoided in finding the triplets. At a cost of speed loss, the algorithm can search to find hypotenuse lengths satisfying x^2+y^2==z^2, rather than calculating z. Of course that doesn't help in locating those meeting the perimeter and area restriction.