Write a Maple code in order to find all the at most three digits Pythagorean triples (a, b, c)
, for
a, b, c > 0
. We say that an integer triple(a, b, c)
is a Pythagorean triple if a^2+b^2=c^2
.
Hint: You might need to use the command type(sqrt(x),integer)
as it returns true if x
is a complete square. Get help for type from the help center.
Asked
Active
Viewed 108 times
-4
-
1Where have you gotten stuck with this assignment? – Jason Aller Oct 14 '19 at 06:00
-
Welcome to Stack Overflow! You seem to be asking for someone to write some code for you. Stack Overflow is a question and answer site, not a code-writing service. Please [see here](http://stackoverflow.com/help/how-to-ask) to learn how to write effective questions. – Federico klez Culloca Oct 16 '19 at 09:39
2 Answers
1
one possibility. You can try to make it more efficient if needed.
result:=Array(1..999);
n:=0;
for a from 1 to 999 do
for b from a to 999 do
c:=sqrt(a^2+b^2);
if type(c,integer) and length(c)<=3 then
n:=n+1;
result(n):=[a,b,c];
fi;
od;
od;
result:=result(1..n);
To print them
for item in result do
print(item[1]^`2`+item[2]^`2`=item[3]^`2`)
od
....

Nasser
- 12,849
- 6
- 52
- 104
-1
Consider this:
isolve(a^2+b^2=c^2);
-
Please provide some explanation to your code. This will confuse anyone who sees it firsthand – shuberman Oct 16 '19 at 09:45
-
@mishsx How does my answer confuse? It is pure Maple code. Maple has built-in solution to the pythagorean triples problem. Have you used this code in Maple? – Christian Wolinski Jul 29 '23 at 20:23