>From: gotoken / math.sci.hokudai.ac.jp (GOTO Kentaro) >Reply-To: ruby-talk / netlab.co.jp >To: ruby-talk / netlab.co.jp (ruby-talk ML) >Subject: [ruby-talk:03599] Re: Another small quiz >Date: Thu, 22 Jun 2000 07:40:42 +0900 (JST) > >Hi, > >In message "[ruby-talk:03597] Re: Another small quiz" > on 00/06/21, "Dat Nguyen" <thucdat / hotmail.com> writes: > >I prefer: > >def fact(n) > > if n < 0 > > raise "argument negative" > > end > > fact = 1 > > for i in 2..n > > fact *= i > > end > > fact > >end > >The avobe fails fact(0) and fact(1) ;-) Really? According to definition: fact(0) is 1. fact(1) is 1*1, also 1. Both are produced by the above :-) Have you tried it? Dat > >def fact(n) > if n > 1 > fact = 1 > for i in 2..n > fact *= i > end > fact > elsif n >= 0 > 1 > else > raise ArgumentError, "argument negative (#{n})" > end >end > >-- Gotoken > ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com