August 25th, 2008

decision, morality, wwtdd?, doctor who

Can somebody check my logic?

It's been years since I've done anything programmy. This isn't meant to be in any particular programming language. Just assume "int xxxx(int A, int B)" defines a function xxxx that takes two integers and returns one.

Would the following "program" determine the Pythagorean triplet {A,B,C} (i.e., a trio of natural numbers that could satisfy the Pythagorean theorem) such that A+B+C=1000?

{
A == 1
B == 1
display A
display B
display Pythag(A,B)
}

int Pythag(int A, int B) {
C == 1000 – A – B
if (sqrt(A^2+B^2)=C^2) {
return C
else {
B++
if (1000 – A – B < 1) {
A++
B == 1
}
Return Pythag(A,B)
}
}
}