
-----------------------------------
mike cra
Wed Oct 20, 2010 7:11 pm

Turing Program
-----------------------------------
I was able to do Permutations n combination

Anyone able to do the GCD or LCM or the Number Theory? I have no clue :S

-----------------------------------
SNIPERDUDE
Wed Oct 20, 2010 10:42 pm

RE:Turing Program
-----------------------------------
Let's tackle this one at a time then. Starting with LCM, what have you tried? What aspect are you stuck with? We can't do your homework for you, but we can help you understand whatever it is you're stuck on.

-----------------------------------
Carey
Thu Oct 21, 2010 6:56 pm

RE:Turing Program
-----------------------------------
For GCD, you'll want to use [url=http://en.wikipedia.org/wiki/Recursion#Recursion_in_computer_science]recursion and [url=http://en.wikipedia.org/wiki/Greatest_common_divisor#Using_Euclid.27s_algorithm]Euclid's Algorithm

Example (pseudo-code, will not run):
[code]
fcn gcd (a, b :int) : int
   if b is 0 then return a
   if anything else then return gcd (b, a mod b) %this is the recursive call. It will call the function from inside itself. At first it's hard to wrap your head around.
end
[/code]

You can then use the GCD method in finding the LCM by following the formula [url=http://en.wikipedia.org/wiki/Least_common_multiple#Reduction_by_the_greatest_common_divisor]here
