From: Todd Benson Date: 2008-02-29T02:08:41+09:00 Subject: Re: Math problem On Wed, Feb 27, 2008 at 4:21 PM, Rick DeNatale wrote: > On 2/27/08, Pit Capitain wrote: > > 2008/2/27, Rick DeNatale : > > > > > Not exactly the fastest way to do it empirically, why random. > > > > > (...) > > > > Rick, are you sure? > > > > Well except in the case where some ZERO cleverly seeds the random > number generator to produce the right random numbers, yes! A very > slight modification: > > def init_counts > zero = 0 > > @counts = Hash.new(zero) > end > > produces: > > > father: 48 daughter: 12 > Father is 48 years old, Daughter is 12. > > rick: 12 loops > thomas: 19467 loops > > > Of course, being random, the thomas count varies, while the rick count > stays at 12. > > And then I much prefer the algebraic solution I worked out in a few > seconds on paper when the question was first posed. > > I leave to others the pleasure of discovering the details of your trick. > > > > > -- > Rick DeNatale > I think Rick's approach is best and makes the most sense. We make a couple of assumptions, but it's very quick (compared to mine ). I don't think, however, it would scale to more dimensions (i.e. comparing x and y and z and maybe even w). The speed difference, though, for this problem, is markedly different (like a factor of four) . Todd