From: Jeff Wood Date: 2005-12-24T04:57:39+09:00 Subject: Re: Why not Python? (No, no, I am not a spy) ------=_Part_13058_6536305.1135367845542 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline uh, yeah, that's what I meant ... darn'd quickie code always bites me in th= e butt ... j. On 12/23/05, Jacob Fugal wrote: > > On 12/23/05, Jeff Wood wrote: > > # complete recursive: > > > > def factorial( x ) > > return 0 if x < 1 > > x * factorial( x - 1 ) > > end > > > > # tail-recursive: > > > > def factorial( x, sum =3D 1 ) > > return 0 if x < 1 > > factorial( ( x - 1 ), ( sum * x ) ) > > end > > > > # iterative: > > > > def factorial( x ) > > sum =3D 1 > > for i in (1..x).to_a > > sum *=3D i > > end > > end > > With bugfixes: > > # complete recursive: > def factorial( x ) > return 1 if x < 1 > x * factorial( x - 1 ) > end > > # tail-recursive: > def factorial( x, sum =3D 1 ) > return sum if x < 1 > factorial( ( x - 1 ), ( sum * x ) ) > end > > # iterative: > def factorial( x ) > sum =3D 1 > for i in (1..x).to_a > sum *=3D i > end > sum > end > > :) > > Jacob Fugal > > -- "Remember. Understand. Believe. Yield! -> http://ruby-lang.org" Jeff Wood ------=_Part_13058_6536305.1135367845542--