Group Abstract Group Abstract

Message Boards Message Boards

Define myEuclid as GCD of two numbers

GROUPS:
Hello,
Euklid[a0_, b0_] :=
  Module[
     {a = a0, b = b0},
     While[a*b != 0, {a, b} = {b, Mod[a, b]}];
     a
        ];

did work fine. How can I define a new function that gives me the GCD of two numbers without using the command "Module" and without using the way above when it says "{a,b} = {b, Mod[a,b]}". I mean: Without writing two commands into { and }. I separately want to tell mathematica: a = b   and   b = Mod[a,b].

Thank you for your help emoticon
POSTED BY: K L
Answer
6 months ago
Not clear to me what you want. Maybe something recursive like below?
gcd[1, _] = 1;
gcd[_, 1] = 1;
gcd[a_, a_] := a
gcd[a_, b_] := gcd[b, Mod[a, b]]
POSTED BY: Daniel Lichtblau
Answer
6 months ago
Hi,

I'd like something that goes in this direction that uses "While" or something like this.
gcd[a_,b_] :=
      If[a==b,Print[b], While[b!=0,If[a>b,...

I just don't get it ;/
POSTED BY: K L
Answer
6 months ago