How many distinct integer triangles can be placed on a 40 x 40 grid if their vertices are required to be on grid intersections? A distinct integer triangle is a triangle with integer sides expressed as an unordered tuple. i.e. a (3,4,5) triangle is the same as a (4,3,5) triangle. As an example, there are only two such triangles on a 7x7 grid.
Bonus: Generalize to n × n grid.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
When I wrote the problem, I had hoped for a combinatoric solution, but I doubt that is likely now. It's just too hard. My solution is similar to yours, but not written as cleanly. Thanks for taking the time to answer this. Nice code.
Log in to reply
I first tried a combinatoric solution, too, but it got too complicated for me. Maybe someone else will write a solution using that method.
interesting problem. I see an issue with your answer 69. Triangle [13,40,45] is a member of the solution set that your code counts as valid. I do not believe that it is possible to place that triangle on a 40X40 grid. A maximum length 39 is possible between the 1st and the 40th grid intersections. If [13,40,45]is valid then what about [30,40,50] , [29,29,40], [9,40,41] that could also be placed on a grid with 41 intersections i.e. 40 unit spaces between the intersection points. I believe that 68 is the correct answer when the grid is 40X40 intersection points.
Log in to reply
The triangle with vertices A ( 0 , 0 ) , B ( 3 6 , 2 7 ) , C ( 2 4 , 3 2 ) has sidelengths ( 1 3 , 4 0 , 4 5 ) and fits on the grid.
Log in to reply
@Chris Lewis – OK my mistake I missed that possibility. thanks
@Chris Lewis is correct. Also, if you add the line "print(sides, (0, 0), (ax, ay), (bx, by))" between lines 37 and 38 and then run the program it will show one set of coordinates for each set of sides found.
I did this by code as well. There seems to be a bit of a pattern if you look at the average number of triangles as n increases - that is, if it's possible to draw T ( n ) distinct triangles with integer sides on an ( n × n ) grid, n 1 r = 1 ∑ n T ( n )
looks reasonably smooth (it's almost, but not quite, quadratic in n ).
I used a slightly different code so it might be useful to double-check some values; I found T ( 2 0 ) = 1 8 , T ( 3 0 ) = 4 2 , T ( 5 0 ) = 1 2 2 and T ( 1 0 0 ) = 3 9 7 . Do these agree with yours?
Log in to reply
Nice observations! And yes, I found all of the same values as you did for T.
Log in to reply
Great, thanks for checking. Just a few more thoughts: the way I set up my code was to start with a small grid, then gradually increase the grid size. If a particular triangle is possible in an n × n grid, but not in an ( n − 1 ) × ( n − 1 ) grid, two of its vertices would have to be on opposite edges of the grid; ie they'd have coordinates ( 0 , a ) and n , b ) for some a and b (in fact we can take a = 0 wlog). (It's still necessary to check each triangle is "new".) This meant fewer points to scan overall, as there weren't as many (say) 3 , 4 , 5 triangles to count, and also (helpfully) built a list of T ( n ) values along the way. So this could lead to a kind of induction argument.
There are three types of triangle to count: those with two sides parallel to the coordinate axes; those with one side parallel; and those with none. It might help to consider these separately for counting purposes, except...
...the fly in the ointment with both of these is that it's possible for the same triangle to appear in more than one orientation. For example, the triangles with vertices ( 0 , 0 ) , ( 1 5 , 0 ) , ( 0 , 2 0 ) and ( 0 , 0 ) , ( 9 , 1 2 ) , ( 2 5 , 0 ) have the same sidelengths, so there's a risk of double-counting.
So far I've only really looked at counting the triangles by scanning gridpoints. An alternative would be to scan all possible distinct triangles with integer sides to see which fit on gridpoints. I guess for each triangle that can fit on gridpoints, there's a smallest n × n grid that it can go on; but I'm not sure if this is a helpful approach.
Fine problem. Try to add T(1),T(2)....... in https://oeis.org/
Problem Loading...
Note Loading...
Set Loading...
The following Python computer program uses brute force to find 6 9 distinct integer triangles: