From: vanjac12@... (Van Jacques) Date: 2003-12-12T22:27:04+09:00 Subject: Re: prog for g.c.d. of 2 integers Florian Pflug writes > a,b=b,a%b while (b != 0) > a.abs This works well, and either a or b (or both) can be < 0. I note that a%b < 0 if b < 0, but it's still OK. g.c.d. are postive though, so a.abs is the g.c.d. after the while statement has executed. My text says that a > b, but (I think) that is so that the Euclidean algorithm, r_i = r_(i-2) % r_(i-1), for i >=2, can include a = r_0 and b = r_1 and then say that r_0 > r_1 > ... > r_n > 0 must terminate with the g.c.d r_n. (r_n | r_(n-1) or r_(n-1) % r_n = 0.) Josef 'Jupp' SCHUGT writes; >> Topics from mathematics make good practice programs, IMO. >I don't agree with that. When starting with mathematics the most >important task of programming has already taken place: The modelling >of the problem in an abstract way. This is a good point. In a ruby tutorial by Camerra (sp?), his example of an addressbook is a good non-math example. As a physicisct and amateur mathematician I have done many math programs, whence comes my prejudice. I will probably continue to do these kinds of problems, since they help me learn abstract algebra, groups, and number theory, but I will try to think up some other kinds of problems, like the addressbook. (Or the song player I saw somewhere.) Both your solutions look fine to me. m / gcd(m, n) * n -- I assume, as in C, equal precedence ops. are left associative. I would write m*n/gcd(m,n) . Van