This Python program checks all possible combinations of three numbers from 1 to 10 and identifies which ones can form an isosceles triangle.
An isosceles triangle has two equal sides and one different side, and must satisfy the triangle inequality:
For any three sides a, b, c, they form a triangle if:
\[
a + b > c,\quad a + c > b,\quad b + c > a
\]
from itertools import combinations_with_replacement
def is_triangle(a, b, c):
return a + b > c and a + c > b and b + c > a
def is_isosceles(a, b, c):
return (a == b or b == c or a == c) and not (a == b == c)
def find_isosceles_triangles(digits):
valid = []
for combo in combinations_with_replacement(digits, 3):
a, b, c = sorted(combo)
if is_triangle(a, b, c) and is_isosceles(a, b, c):
valid.append((a, b, c))
return valid
# Run the program
digits = list(range(1, 11))
isosceles = find_isosceles_triangles(digits)
print(f"Number of isosceles triangles: {len(isosceles)}")
for tri in isosceles:
print(f"Triangle: {tri}")
Number of isosceles triangles: 24
Triangle: (2, 2, 3)
Triangle: (2, 3, 3)
Triangle: (3, 3, 4)
...
- All 3-number combinations with repetition are generated from digits 1 to 10
- Each combination is checked for triangle validity using the triangle inequality
- Then it’s checked whether exactly two sides are equal (isosceles)
- Valid triangles are printed along with the total count