Project Euler 91 - Right Triangles with integer co-ordinates

Official link:

Thought Process

Let A = (0,0), B = (x1, x2), C = (y1, y2)

Choose point B and C randomly, then

AB = sqrt(x1^2 + x2^2)

AC = sqrt(y1^2 + y2^2)

BC = sqrt((x1-y1)^2 + (x2-y2)^2)

Then if (maximum(AB, AC, BC))^2 = other 2 squared then this forms a right angle triangle. Then I go through each point which would be ~ 6,760,000 combinations

I omit sqrt when calculating AB, AC, BC because if x > y > 0 => x^2 > y^2

My solution takes ~ 6 seconds, there are much faster and smarter ways to do this problem using dot product and making some smart observations. I recommend reading one of my inspirations, Stephan Brumme's, page on this problem for a smarter approach.

Interactive Code

Input an integer (yourinput)

Code will output number of right angle triangles can be formed when all points are <= yourinput