# Least Common Multiple

Hi folks, can anyone who is a maths savvy help me. I’m after a bit of code to calculate the least common multiple given 3 numbers.

Sorry I know this is a lazy request but i’ve been scratching my head for too long now and hoping someone has done this before. I suspect its only 5 or 6 lines of code.

Thanks Wolfram even has fancy math-people pictures http://mathworld.wolfram.com/LeastCommonMultiple.html

[quote=244770:@Tim Parnell]http://bfy.tw/43WY
and
http://goo.gl/NieUbu

Wolfram even has fancy math-people pictures http://mathworld.wolfram.com/LeastCommonMultiple.html[/quote]

Thanks Tim, I was being lazier than that, I was after the code…

I could not find an example in Xojo specifically, but I did find code to do this in several dozen other languages, any of which should be easy enough to adapt: http://bfy.tw/43Y3

Kimball,

How rude! How funny! Where can I do that? Can you Google that for me?

(I figured it out, thanks.)

Of course, the best response to your question of how to do that would have been… http://bfy.tw/5z

It’s what I was waiting for, actually. You blew it!

I figured I’d already hit my snarky quota for this thread. I should try to remember that when responding to you there is no snarky quota. http://bfy.tw/43Yq [code] dim tongueInCheek as Boolean = True
dim willThisReallyWork as Boolean = False
dim http as new HTTPSocket
dim x, y, z as integer
dim url, toScrape as string
dim rg as new regex
dim rgm as regexmatch

x = 14
y = 5
z = 92

url = “http://www.wolframalpha.com/input/?x=0&y=0&i=LCM[” + str(x) + “,+” + str(y) + “,+” + str(z) + “%5D”
toScrape = http.Get(url, 30)[/code]

`` MsgBox(rgm.subexpressionstring(0).stringvalue)``

@Scott Griffitts - oh, oh, I know this one! It’s 3220!

Nah, Its not working Scott You couldn’t have a play about with it for me could you and let me know when you get it working Why am I weirdly considering doing exactly this? MUST. NOT. CAVE…

Ok, so I ended up doing the hard work for me. If anyone needs to know in future LCM for 3 numbers can be calculated by:

[code]Function LCM(a as integer, b as integer, c as integer) As int64
//Least common multiplier

Dim resAB as Int64

resAB = a*b/GCD(a,b)

return resAB*c/GCD(resAB,c)

End Function
[/code]

[code]Function GCD(a as integer, b as integer) As integer
//greatest common diviser

Dim tmpA as Double
Dim tmpB as Double

while b > 0

``````tmpA = b
tmpB = a mod b

a = tmpA
b = tmpB
``````

wend

Return a

End Function
[/code]