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

Home > Just Math
Maximal number of solutions (Posted on 2018-12-08) Difficulty: 4 of 5
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
{20,48,52}, {24,45,51}, {30,40,50}

For which value of p ≤ 1000, is the number of solutions maximized?

Source: Project Euler

See The Solution Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Basic language solution Comment 5 of 5 |
In the below, the lines

         If p = 840 Then
            Text1.Text = Text1.Text & Str(sm) & Str(lg) & Str(h) & crlf
         End If

were added after the second part found the highest was uniquely 840.

The result of those line is the first part of the ultimate output:

 240 252 348
 210 280 350
 168 315 357
 140 336 364
 120 350 370
 105 360 375
 56 390 394
 40 399 401
24 1
30 1
36 1
40 1
48 1
56 1
60 2
84 2
90 2
120 3
168 3
180 3
240 4
360 4
420 5
660 5
720 6
840 8

where the second part is the new highest value as triangles were tested with ever increasing larger perimeters and within that increasing larger legs.

 Max = 1
 
 For p = 15 To 1000
   For lg = 1 To p / 2
     For sm = 1 To lg
       DoEvents
       h = p - lg - sm
       If h < lg Then Exit For
       If sm * sm + lg * lg = h * h Then
         ct(p) = ct(p) + 1
         If p = 840 Then
            Text1.Text = Text1.Text & Str(sm) & Str(lg) & Str(h) & crlf
         End If
       End If
     Next
   Next lg
 Next p
 For i = 1 To 1000
   If ct(i) >= Max Then
     Text1.Text = Text1.Text & i & Str(ct(i)) & crlf
     Max = ct(i)
   End If
 Next

  Posted by Charlie on 2018-12-09 10:13:45
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 (3)
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