From: Josef 'Jupp' SCHUGT Date: 2003-12-12T07:19:18+09:00 Subject: Re: prog for g.c.d. of 2 integers Hi! * Van Jacques; 2003-12-11, 14:14 UTC: > 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. > Comments are welcome. My implementations are these: def Extmath.gcd(m, n) m = Integer(m) n = Integer(n) if m <= 0 || n <= 0 return nil end loop { if m < n m, n = n, m end if (l = m % n) == 0 break end m = l } n end def Extmath.lcm(m, n) m = Integer(m) n = Integer(n) if m <= 0 || n <= 0 return nil end m / gcd(m, n) * n end They are part of extmath - http://extmath.rubyforge.org/ Josef 'Jupp' SCHUGT -- http://oss.erdfunkstelle.de/ruby/ - German comp.lang.ruby-FAQ http://rubyforge.org/users/jupp/ - Ruby projects at Rubyforge