From: Roelof Wobben Date: 2012-09-26T03:35:57+09:00 Subject: Re: inject problem --_758886cd-d49e-466a-a5e9-8c1520eeea2d_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable thanks=2C=20 The only problem I have to solve is when dice is a empty array.=20 you now get [] as answer but the answer has to be 0.=20 Roelof > Date: Wed=2C 26 Sep 2012 03:17:56 +0900 > From: sandor.szuecs@fu-berlin.de > Subject: Re: inject problem > To: ruby-talk@ruby-lang.org >=20 > On 9/25/12 4:18 PM=2C Roelof Wobben wrote: > >=20 > > Hello=2C=20 > >=20 > > One question so I can understand this way well. > >=20 > > In this context x =3D 1 or 2 and y is the place in the hash ? >=20 > irb> array.inject({}){|x=2Cy| puts "x:#{x}=2C y:#{y}"=3B x[y] +=3D 1 resc= ue x[y] > =3D 1=3B x} > x:{}=2C y:1 > x:{1=3D>1}=2C y:2 > x:{1=3D>1=2C 2=3D>1}=2C y:1 > x:{1=3D>2=2C 2=3D>1}=2C y:1 > =3D> {1=3D>3=2C 2=3D>1} >=20 >=20 >=20 > >=20 > > Roelof > >=20 > >=20 > >> Date: Tue=2C 25 Sep 2012 22:04:50 +0900 > >> From: peterhickman386@googlemail.com > >> Subject: Re: inject problem > >> To: ruby-talk@ruby-lang.org > >> > >> just do: > >> > >> array =3D [ 1=2C 2 =2C 1 =2C 1] > >> > >> p array.inject({}){|x=2Cy| x[y] +=3D 1 rescue x[y] =3D 1=3B x} > >> > > =20 > >=20 >=20 >=20 > --=20 > Viele Gr=FC=DFe Sandor >=20 = --_758886cd-d49e-466a-a5e9-8c1520eeea2d_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
thanks=2C

The only problem I have to solve is when dice is a empty = array.
you now get [] as answer but the answer has to be 0.

Roe= lof


>=3B Date: Wed= =2C 26 Sep 2012 03:17:56 +0900
>=3B From: sandor.szuecs@fu-berlin.de>=3B Subject: Re: inject problem
>=3B To: ruby-talk@ruby-lang.org<= br>>=3B
>=3B On 9/25/12 4:18 PM=2C Roelof Wobben wrote:
>=3B &= gt=3B
>=3B >=3B Hello=2C
>=3B >=3B
>=3B >=3B One qu= estion so I can understand this way well.
>=3B >=3B
>=3B >= =3B In this context x =3D 1 or 2 and y is the place in the hash ?
>= =3B
>=3B irb>=3B array.inject({}){|x=2Cy| puts "x:#{x}=2C y:#{y}"= =3B x[y] +=3D 1 rescue x[y]
>=3B =3D 1=3B x}
>=3B x:{}=2C y:1
= >=3B x:{1=3D>=3B1}=2C y:2
>=3B x:{1=3D>=3B1=2C 2=3D>=3B1}=2C y= :1
>=3B x:{1=3D>=3B2=2C 2=3D>=3B1}=2C y:1
>=3B =3D>=3B {1= =3D>=3B3=2C 2=3D>=3B1}
>=3B
>=3B
>=3B
>=3B >= =3B
>=3B >=3B Roelof
>=3B >=3B
>=3B >=3B
>=3B = >=3B>=3B Date: Tue=2C 25 Sep 2012 22:04:50 +0900
>=3B >=3B>=3B= From: peterhickman386@googlemail.com
>=3B >=3B>=3B Subject: Re: i= nject problem
>=3B >=3B>=3B To: ruby-talk@ruby-lang.org
>=3B = >=3B>=3B
>=3B >=3B>=3B just do:
>=3B >=3B>=3B
>= =3B >=3B>=3B array =3D [ 1=2C 2 =2C 1 =2C 1]
>=3B >=3B>=3B
= >=3B >=3B>=3B p array.inject({}){|x=2Cy| x[y] +=3D 1 rescue x[y] =3D = 1=3B x}
>=3B >=3B>=3B
>=3B >=3B
>=3B >= =3B
>=3B
>=3B
>=3B --
>=3B Viele Gr=FC=DFe Sandor>=3B
= --_758886cd-d49e-466a-a5e9-8c1520eeea2d_--