GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2017-05-31 19:46:44

JFitch
Member
Registered: 2017-05-31
Posts: 2

gcf

Expand///gcf(a, b, c, d, e, ...)
//
// Returns the greatest common factor of the arguments
// by continuing to replace the larger of the first two numbers with the remainder when dividing by the smaller until you get a remainder of 0
// once you find the gcf of the first two numbers, you find the gcf of the result and the third number, then the gcf of the result and the fourth number, etc
//
// Code by JFitch
/// GMLscripts.com/license

{
var a=argument[0];
var b;
var new_a;
var new_b;
var i;

for (i=1;i<argument_count;i++)
{
b=argument[i];

while (a!=b && a!=0 && b!=0)
{
new_a=a mod b;
new_b=b mod a;
a=new_a;
b=new_b;
}
a=max(a,b);
}
return a;
}

Offline

#2 2017-06-06 12:11:42

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: gcf

Thanks for the submission JFitch and welcome to the forums.

There is already a gcd script but yours takes more than two arguments. I'll probably add your changes to the existing script.


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB