From: Joey Date: 2006-05-16T16:44:39+09:00 Subject: Re: stack level too deep (SystemStackError) ------=_Part_58099_31840156.1147765476512 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The last bit could be changed to: print f.map{|x|x.is_a?(Array) ? "(#{x.join(" x ")})" : x}.join(" x ") To add the correct brackets. J`ey http://www.eachmapinject.com On 5/16/06, john s wrote: > > When writing a code to find the factor of a given number, i ran into the > following error message: > > "factor.rb:48: parse error, unexpected kEND, expecting $" > > > I was hoping someone could shed light on the problem. Heres the code: > > def isprime testNum > testWith =3D 2 > run =3D 1 > while testNum > testWith and run =3D=3D 1 > prime =3D testNum % testWith > if prime !=3D 0 > testWith =3D testWith + 1 > else > run =3D 2 > end > end > > if prime !=3D 0 > return true > else > return false > end > end > > > def factor toFactor > factored =3D false > numbers =3D Array.new > numbers.push toFactor > testWith =3D 2 > while factored =3D=3D false and numbers.last > testWith > test =3D numbers.last > isFactor =3D numbers.last%testWith > if isFactor =3D=3D 0 > numbers.pop > numbers.push(testWith) > numbers.push(test/testWith) > factored =3D true > else > testWith =3D testWith + 1 > end > end > > eval =3D numbers.last > if isprime(eval) =3D=3D false > numbers.pop > add =3D factor(eval) > numbers.push(add) > end > end > > numbers > end > > > f =3D factor(100) > > > puts f.join(' x ') > _____________________________________________________________________ > Note: subsituting " eval =3D numbers.last" for "numbers.each do |eval| > "avoids the error. > > Please Help! > > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_58099_31840156.1147765476512--