Integer right triangles
2014-09-24
Problem 039: Integer right triangles
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 maximised?
Solution:
v
>010p020p630p"d"55+*90p050p30g3/70p v
vp07/3g03p050 p03+2<
v ># v# p07-1< >10p30g20pv
>30g::270g*-*\70g-2*%#^_50g1+50p>70g:2-#^_$50g:10g`#^_$ >30g:90g-|
> $^$ < @.g02$<
>010p020p630p"d"55+*90p050p30g3/70p v
vp07/3g03p050 p03+2<
v ># v# p07-1< >10p30g20pv
>30g::270g*-*\70g-2*%#^_50g1+50p>70g:2-#^_$50g:10g`#^_$ >30g:90g-|
> $^$ < @.g02$<
Start
??
Pause
Reset
Output:
Stack: (0)
Explanation:
We have the two formulas a^2 + b^2 = c^2
and a + b + c = p
. We can insert the second in the first and get b = p*(p-2a) / 2*(p-a)
and c = p-(b+a)
.
The we just go through all possible values for a and p and test if b is an integer. Then we search for the value of p with the most possible values of a.
Interpreter steps: | 3 815 878 |
Execution time (BefunExec): | 827ms (4.61 MHz) |
Program size: | 72 x 6 (fully conform befunge-93) |
Solution: | 840 |
Solved at: | 2014-09-24 |