Hello,
I have come across a problem that I don't have an elegant solution for...
The question is: Given a square 4 x 4 grid of dots, how many right angled triangles can you create by selecting three dots?
You could of course use a brute force method. I have considered permutations / combinations, but ran into some difficulties of eliminating solutions. I've considered approaching it through a symmetrical approach as well.
Any help on the problem will be very helpful!
Easy Math Editor
This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.
When posting on Brilliant:
*italics*
or_italics_
**bold**
or__bold__
paragraph 1
paragraph 2
[example link](https://brilliant.org)
> This is a quote
\(
...\)
or\[
...\]
to ensure proper formatting.2 \times 3
2^{34}
a_{i-1}
\frac{2}{3}
\sqrt{2}
\sum_{i=1}^3
\sin \theta
\boxed{123}
Comments
@Jae Joon Chang - Here is the solution-
Basically what we are looking for is the number of sets of 3 points within 16 points minus the sets of 3 points that lie on the same line, or in other words are collinear.
The number of sets of 3 points within the 4x4 grid is C316=560
Now, on each vertical and horizontal line, there are 4 ways that you can choose 3 collinear points (Proof given at the end)
There are 4 vertical lines, and 4 horizontal lines, so the number of sets here is 4×4×2=32
The grid has two main diagonals, and four minor diagonals (Shown in an image at the end)
Again, there are 4 ways that 3 collinear points can be chosen on the main diagonals, and 1 way on each of the minor diagonal lines.
This means, that the number of sets on the diagonals is 2×4+4=12
Thus, the answer is 560−32−12=516 triangles
Images -
These are the 4 ways you can choose a set of 3 collinear points on a line
The green lines are the minor diagonals
Sorry for bad artistic skills :)
Log in to reply
@Percy Jackson - thanks for your solution. I think the 516 triangles are simply triangles, whereas the question wanted to find the number of potential right angled triangles you can get.
A friend of mine ran a C++ programme finding three points that satisfies Pythagoras' Theorem and it returned with 200 right angled triangle.
I like the idea of eliminating collinear points, but I'm not too sure on how you could look to eliminate points that create a scalene triangle.
Log in to reply
Oh! Right angled triangles! I missed that part. Yes, then it would be difficult to eliminate all other triangles which are not right angled...Can you share the C++ code with me if its possible?
Log in to reply
IN: import itertools
IN: def is_right(a,b,c): ab2 = (a[0]-b[0])(a[0]-b[0]) + (a[1]-b[1])(a[1]-b[1]) ac2 = (a[0]-c[0])(a[0]-c[0]) + (a[1]-c[1])(a[1]-c[1]) bc2 = (b[0]-c[0])(b[0]-c[0]) + (b[1]-c[1])(b[1]-c[1]) s = sorted((ab2, ac2, bc2)) return (s[0] + s[1] == s[2] and a != b and a != c and b != c)
IN: def righttriangles (x, y): return {frozenset((a, b, c)) for (a, b, c) in itertools.product( itertools.product(range(x), range(y)), itertools.product(range(x), range(y)), itertools.product(range(x), range(y)) ) if isright(a, b, c)}
IN: len(right_triangles(4, 4))
Log in to reply
I ran a simple python program and I got only 32 lol
Log in to reply
It outputted 192 but since every triangle was counted six times, the answer according to me should be surprisingly just 32, please tell me if the program is wrong ( pretty sure it is given the number solutions your friend predicted )
Log in to reply
I think you've got precision problems with floats. Rerun it with d2 instead of dist, where you don't take square roots (and drop the squares from the if statements in the loop). I did that myself, and I got 200.
The answer has to be at least 144; pick a point to be the right-angle point, and then pick a point on the vertical line and a point on the horizontal line from that point. There are 16⋅3⋅3 choices. And that ignores triangles like (0,0),(1,1),(2,0).
Log in to reply
Log in to reply
Log in to reply
Log in to reply