Thread: lcm and gcd
View Single Post
Old 6th August 2011, 18:17   #1  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
lcm and gcd

Quick utilities if you're ever searching for them (I was)
Code:
x=42
y=36
parms=str_bracket(string(x)+","+string(y))+"="
messageclip("lcm"+parms+string(lcm(x,y))+"; gcd"+parms+string(gcd(x,y)))

function gcd(int x, int y){
	t = x%y
	x = y
	y = t
	return (y>0)?gcd(x,y):x
}

function lcm(int x, int y){
  y*abs(x)/gcd(x,y)
}

function str_bracket(string s){
  "("+s+")"
}
jmac698 is offline   Reply With Quote