Jump to content

Pythagorean triples: Difference between revisions

m
(C++ entry)
Line 3,019:
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Short code but not a very scalable approach...
<lang Mathematica>pythag[n_] := Block[{soln = Solve[{a^2 + b^2 == c^2, a + b + c <= n, 0 < a < b < c}, {a, b, c}, Integers]},
{Length[soln], Count[GCD[a, b] == GCD[b, c] == GCD[c, a] == 1 /. soln, True]}
]</lang>
 
{{out}}
<pre>pythag[10]
{0,0}
 
pythag[100]
{17, 7}
 
pythag[1000]
{325, 70}</pre>
1,111

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.