Blockland Forums > Modification Help
Greatest Common Factor in TorqueScript?
Pages: (1/1)
Axolotl:
Using my resources, how do I get the Greatest Common Factor?
The function uses 2 arguments.
Headcrab Zombie:
Here's an untested port from a c++ program a did a while back
--- Code: ---function gcf(%a,%b)
{
for(%i=1;%i<=%a;%i++)
{
if(%a % %i == 0 && %b % %i == 0)
%gcf = %i;
}
return %gcf;
}
--- End code ---
phflack:
you're missing a few % signs in front of the i's, but besides that it looks like it should work
although i don't think you need the && %i > %gcf in the if statement, it should always return true
Headcrab Zombie:
Fixed that.
Not sure what I was thinking with the last part
Axolotl:
Thank you
Pages: (1/1)