From: Roelof Wobben Date: 2012-09-26T20:11:32+09:00 Subject: Re: inject problem --_365739d9-4b6c-4dce-a2f8-2849270e14f5_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Interresting idea. I will try if I can make it work this afternoon or this evening. Roelof > Date: Wed=2C 26 Sep 2012 18:44:24 +0900 > From: jgabrielygalan@gmail.com > Subject: Re: inject problem > To: ruby-talk@ruby-lang.org >=20 > On Wed=2C Sep 26=2C 2012 at 9:39 AM=2C Roelof Wobben wrote: > > Now refractor the if then 's and I hope I can decline it to less then 5= if > > then's. > > But that will be difficult. >=20 > I think you should not structure the code this way. I think you should > loop through the counts=2C finding and removing sets. Something like > (pseudocode): >=20 > while there are sets of 3 ones: > remove the set from the hash (h[1] -=3D 3) > sum 1000 to the score > end >=20 > while there are sets of 3 any other pip count: > remove the set from the hash (h[x] -=3D 3) > sum 100*x to the score > end >=20 > sum 100 * (remaining number of ones) > sum 50 * (remaining number of fives) >=20 > This way=2C your code is more simple and robust. For example this will > also work if you throw 9 dice=2C while your current algorithm does not. >=20 > Jesus. >=20 = --_365739d9-4b6c-4dce-a2f8-2849270e14f5_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Interresting idea.

I will try if I can make it work this afternoon o= r this evening.

Roelof


>=3B Date: Wed=2C 26 Sep 2012 18:44:24 +0900
>=3B From: jga= brielygalan@gmail.com
>=3B Subject: Re: inject problem
>=3B To: r= uby-talk@ruby-lang.org
>=3B
>=3B On Wed=2C Sep 26=2C 2012 at 9:3= 9 AM=2C Roelof Wobben <=3Brwobben@hotmail.com>=3B wrote:
>=3B >= =3B Now refractor the if then 's and I hope I can decline it to less then 5= if
>=3B >=3B then's.
>=3B >=3B But that will be difficult.>=3B
>=3B I think you should not structure the code this way. I t= hink you should
>=3B loop through the counts=2C finding and removing s= ets. Something like
>=3B (pseudocode):
>=3B
>=3B while ther= e are sets of 3 ones:
>=3B remove the set from the hash (h[1] -=3D 3= )
>=3B sum 1000 to the score
>=3B end
>=3B
>=3B whil= e there are sets of 3 any other pip count:
>=3B remove the set from = the hash (h[x] -=3D 3)
>=3B sum 100*x to the score
>=3B end
= >=3B
>=3B sum 100 * (remaining number of ones)
>=3B sum 50 * (= remaining number of fives)
>=3B
>=3B This way=2C your code is mo= re simple and robust. For example this will
>=3B also work if you thro= w 9 dice=2C while your current algorithm does not.
>=3B
>=3B Jes= us.
>=3B
= --_365739d9-4b6c-4dce-a2f8-2849270e14f5_--