Quantcast
Channel: stardot.org.uk
Viewing all articles
Browse latest Browse all 5552

programming • Re: Weekend coding challenge: collecting twin triangles

$
0
0
(Yep, first quad found is 236 ...
I'll admit that I dropped some results to Ed by PM yesterday. Amongst my results I found the following quadruplets:
  • (46, 93, 97); (48, 88, 100); (55, 78, 103); (64, 68, 104)
  • (50, 93, 113); (53, 89, 114); (58, 83, 115); (60, 82, 118)
  • (58, 100, 102); (60, 94, 106); (66, 85, 109); (74, 76, 110)
I, too, was in there "are you sure there are any solutions to this?" camp until I found out how wrong I was doing it. My code is quite horrible, and vastly unsuitable for micros. On several occasions I ran out or RAM and/or temporary storage on a 32 GB Linux box. There are awk scripts filtering awk scripts filtering awk scripts ...
  1. a small python script generates a list of candidate perimeters, areas and side lengths, the lengths sorted to catch duplicates. For triangles up to sides (100,100, 199) it generates 666,700 lines of output;
  2. after sorting and removing exact duplicates, there are merely 171,700 lines to comb through;
  3. an awk script outputs matches if the area and perimeter from the previous line match the ones on the current line.
For shorter sides up to 100 units, there are 4380 solutions. Some of these are doubtless similar duplicates.

The largest pair I found using this code was (415, 499, 774) ; (454, 459, 775)

I guess you could miss out the square root from Heron's Formula to save some computation time, because Area² will do the job too.

Statistics: Posted by scruss — Sun May 18, 2025 8:24 pm



Viewing all articles
Browse latest Browse all 5552

Trending Articles