From: Roelof Wobben Date: 2012-09-29T21:12:34+09:00 Subject: Re: ibonacci sequence problem --_23f9cde7-4a5d-4c92-9bd0-782a1e5a84e8_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thanks I will try to do that.I have one question about it. Image I have th= is situation.Look for a number which is prime and can be divided by 2. I ca= n do if number =3D=3D prime and even?number then But as I see it if a numb= er is not a prime there is no need to look if it's even.Then I could do if = number =3D=3D prime if even?number p number endend But this lo= oks like a long code for the problem. What's the best ruby way to solve thi= s ? Roelof > Date: Sat=2C 29 Sep 2012 20:18:41 +0900 > From: lists@ruby-forum.com > Subject: Re: ibonacci sequence problem > To: ruby-talk@ruby-lang.org >=20 > Roelof Wobben wrote in post #1077985: > > And the best way for me to learn something is to do it and not only to > > read about it. >=20 > Yes=2C absolutely! And I think my critique was a bit unjust: You've found= =20 > a valid=2C logical solution that works fine (apart from the small "inject= "=20 > mistake). So you've done a good job. >=20 > What I was talking about is the next step: improving the programming=20 > style. When you've found a solution=2C it's always a good idea to try to= =20 > improve it and think about alternative approaches. >=20 > For example=2C you could ask yourself: Do I really need to save all=20 > elements in an array? Or you could look for built-in Ruby methods to=20 > solve the task: How can I create a "sequence object"? How can I select=20 > all elements up to the first one that doesn't fulfill a condition? etc. >=20 > I've found this to very helpful in the learning process. Solving a=20 > problem is one thing. Digging deep into the language to find a better=20 > solution is even better. >=20 > --=20 > Posted via http://www.ruby-forum.com/. >=20 = --_23f9cde7-4a5d-4c92-9bd0-782a1e5a84e8_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Thanks
 =3B
I will try to do that.
I have one question about = it.
 =3B
Image I have this situation.
Look for a number which = is prime and can be divided by 2.
 =3B
I can do =3B if number=  =3B=3D=3D prime and =3Beven?number then
But as I see =3Bit=  =3Bif a number is not a prime there is =3Bno need to look if it's = even.
Then I =3Bcould =3Bdo
if number =3B=3D=3D prime  =3B =3B =3Bif =3Beven?number
 =3B =3B = =3B =3B =3B =3B p number
 =3B =3B =3B end
end=
 =3B
But this looks like a long code for =3Bthe problem.
=  =3B
What's =3Bthe best ruby way to solve this ?
 =3B
= Roelof

 =3B
>=3B= Date: Sat=2C 29 Sep 2012 20:18:41 +0900
>=3B From: lists@ruby-forum.c= om
>=3B Subject: Re: ibonacci sequence problem
>=3B To: ruby-talk= @ruby-lang.org
>=3B
>=3B Roelof Wobben wrote in post #1077985:>=3B >=3B And the best way for me to learn something is to do it and = not only to
>=3B >=3B read about it.
>=3B
>=3B Yes=2C abs= olutely! And I think my critique was a bit unjust: You've found
>=3B = a valid=2C logical solution that works fine (apart from the small "inject" =
>=3B mistake). So you've done a good job.
>=3B
>=3B What I= was talking about is the next step: improving the programming
>=3B s= tyle. When you've found a solution=2C it's always a good idea to try to >=3B improve it and think about alternative approaches.
>=3B
&g= t=3B For example=2C you could ask yourself: Do I really need to save all >=3B elements in an array? Or you could look for built-in Ruby methods = to
>=3B solve the task: How can I create a "sequence object"? How can= I select
>=3B all elements up to the first one that doesn't fulfill = a condition? etc.
>=3B
>=3B I've found this to very helpful in t= he learning process. Solving a
>=3B problem is one thing. Digging dee= p into the language to find a better
>=3B solution is even better.>=3B
>=3B --
>=3B Posted via http://www.ruby-forum.com/.
= >=3B
= --_23f9cde7-4a5d-4c92-9bd0-782a1e5a84e8_--