Calculation of a Triangle with two Unknowns with your Head and with Python

Calculation of a Triangle with two Unknowns with your Head and with Python

You have a triangle, where you only know one site and the angle. This problem comes during a test at the Tesla company of Elon Musk.

This is only an example and this is nothing when you want to build a house. When you want to build a house, then you need one solution and not so many.

The setup:

  • angle = 90 degrees
  • a, b, c are only natural numbers
  • c > b
  • site a = 10 (cm)
  • right-angled triangle

The Mathematical Approach:

We start with the Pythagorean theorem:

a2 + b2 = c2

We have to subtract b2, then we have

a2 = c2 – b2

This part c2 – b2 is a part of the 3. binomial formula. We have to write:

a2 = (c + b) * (c – b)

a2 = 100 = (c + b) * (c – b)

Now we have to find out how often we multiply two numbers when the result is 100

10 * 10 (it is ok, but in this case, it is a triangle and c > b, then this solution is bad)

25 * 4, 20 * 5, 50 * 2, 100 * 1 are good choices.

Then we calculate

c + b = 20

c – b = 5

We use the addition method

(c+b=20)+(cb=5)(c+b = 20) + (c-b = 5)

The interim result is (c+c = 2c) +b – b = nothing = 2c = 25 (20 +5).

Then we 25 / 2 = 12,5

But is 12,5 is not a natural number.

So we have to test with the same way with the other numbers.

In the end we have one result, b = 24 and c = 26.

This is the analog time. But nowadays, we have already computer that can do this work for us. The „only“ difficulty is to order the computer what he should do.

I did with a Python script.

Yes, of course you can do it with other programming languages.

import math

print("Right-angled triangle with two unknown lengths")
print("--------------------------------------------------")

# User input
a = int(input("Enter the length of side A (natural number): "))

# Mathematical basis: a² + b² = c²  =>  a² = c² - b²
# Difference of squares: a² = (c + b) * (c - b)
side_a_squared = a ** 2 

print(f"Searching for solutions for a² = {side_a_squared}...")

solutions_found = 0

# We are looking for divisor pairs (x and y) whose product equals side_a_squared
# range(1, side_a_squared + 1) ensures the number itself is also checked
for x in range(1, side_a_squared + 1):
    if side_a_squared % x == 0:
        y = side_a_squared // x
        
        # Condition 1: y must be the larger part (since y = c + b)
        if y > x:
            # Condition 2: The sum must be even for c to be a natural number
            if (x + y) % 2 == 0:
                c = (x + y) // 2
                b = y - c
                
                # The proof: Calculate a² + b² and check if it equals c²
                proof_left = a**2 + b**2
                proof_right = c**2
                
                solutions_found += 1
                print(f"Solution {solutions_found}: Side b = {b}, Side c = {c}")
                print(f"   -> Proof: {a}² + {b}² = {c}²  ({a**2} + {b**2} = {c**2}) ✅")

if solutions_found == 0:
    print("No solution found with natural numbers.")
else:
    print(f"--- Search finished. {solutions_found} solution(s) found. ---")

This is the output on the screen

Die Kommentare sind geschlossen.