All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Pythagorean Triples #1 (Posted on 2024-01-31) Difficulty: 3 of 5
Find two Pythagorean triples A,B,C and D,E,F such that A+D is a triangular number, B+E is a triangular number, and C+F is a triangular number.

Triangular numbers are numbers of the form N(N+1)/2, such as 1, 3, 6, 10, 15, ... .

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Computer solution Comment 2 of 2 |
It is not stated that each triangle's sides are listed in any particular order, so we have to account for each of the possible pairings.  
There is no constraint that a Pythagorean Triple must be a primitive one.
There is no requirement that the three triangular numbers must be distinct.

The algorithmic trick I used was to assign an integer to any pairing of sides whose sum is a triangular number according to a polynomial involving the two indices.  I chose possible values 1,2,3,10,20,30,100,200,300 (or no value at all if the sum is not triangular).  If there are 3 or more pairings that qualify, each combination of 3 is summed.  If the resulting sum is any 3 digit permutation of 123 (list variable name 'goodsums'), then we have a winning pair of Pythagorean Triples.  The 3 digit pattern corresponds to which side of the first triangle is paired with which side in the second triangle.  If A<B<C and D<E<F, the corresponding 'pattern' is 321.

The sums for each pairing with rows and columns defined by the indices of each triangle:
    0    1    2
0   1   10   100
1   2   20   200
2   3   30   300
    

The smallest triangle combo I found was:
(5, 12, 13) and (24, 32, 40)
Triangular numbers are
5 + 40 = 45
12 + 24 = 36
13 + 32 = 45

The first pair I found where the shortest side is paired with the shortest; the longest with the longest etc, 
if A<B<C and D<E<F:
(35, 84, 91) and (20, 21, 29)

I limited my initial search to triangles with the smallest side < 40.  Out of 70 Pythagorean triples generated, I found 5 pairs of triangles that qualified.  

program output:
  1st triple     2nd triple  'pattern'
[([5, 12, 13], [24, 32, 40]), 132]  <-- smallest I found
[([7, 24, 25], [20, 21, 29]), 123]
[([17, 144, 145], [19, 180, 181]), 231]
[([35, 120, 125], [33, 56, 65]), 312]
[([35, 84, 91], [20, 21, 29]), 321]  <-- smallest I found with A<B<C and D<E<F (pattern 321)

--------------

from itertools import combinations
big = 40
triples = []
biggest = 0
for offset in range(1,101):
    for a in range(offset+2, big, 2):
        if ((a**2 - offset**2)/(2*offset))%1 != 0:
            continue
        b = int((a**2 - offset**2)/(2*offset))
        c = b + offset
        temp = sorted([a,b,c])
        if temp not in triples:
            triples.append(temp)
            if temp[2] > biggest:
                biggest = temp[2]

uppertri = 1 + int((1 + (1+8*biggest)**.5)/2)
tri_numbers = [int(n*(n+1)/2) for n in range(1,uppertri)]

solutions = []
goodsums = [123,132,213,231,312,321]
for comb in combinations(triples,2):
    indicator_sums = []
    for indexA,x in enumerate(comb[0]):
        for indexD,y in enumerate(comb[1]):
            if (x+y) in tri_numbers:
                indicator_sums.append((indexA+1)*10**indexD)
    number_sums = len(indicator_sums)
    if number_sums < 3:
        continue
    for combo in combinations(indicator_sums,3):
        if sum(combo) in goodsums:
            solutions.append([comb, sum(combo)])
            
for sol in solutions:  
    print(sol)

  Posted by Larry on 2024-01-31 15:54:23
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (10)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information