Special Pythagorean triplet
2014-09-11
Problem 009: Special Pythagorean triplet
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^2 + b^2 = c^2
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
Solution:
"d"5:+*00p210p> 120p>v >20g1+:20p10g-#v_10g1+:10p00g-#v_ @
^ <
^ <
v <
>20g:*10g:*+:30p0>::*30g-#v_:30p20g10g++ 00g-#v_20g:." ",10g:." ",30g:."=",**.@
|-g00 :+1<
>$$ ^ $<
^ <
^ <
v <
>20g:*10g:*+:30p0>::*30g-#v_:30p20g10g++ 00g-#v_20g:." ",10g:." ",30g:."=",**.@
|-g00 :+1<
>$$ ^ $<
Start
??
Pause
Reset
Output:
Stack: (0)
Explanation:
The brute-force approach is here taking quite a long time - but I think it's good enough - perhaps I will make an optimized version later
Interpreter steps: | 1 397 212 134 |
Execution time (BefunExec): | 6min 34s (3.54 MHz) |
Program size: | 79 x 7 (fully conform befunge-93) |
Solution: | 31875000 |
Solved at: | 2014-09-11 |