From: Rick DeNatale Date: 2008-02-28T02:35:00+09:00 Subject: Re: Math problem On 2/27/08, Thomas Preymesser wrote: > On 26/02/2008, grandmabeckie@msn.com wrote: > > > > I am try to help my daughter: > > Problem > > > > father is 4 times older then his daughter. > > in 6 years he will be 3 times older what is the answer and how did you > > reach it. > > > > 48 and 12 > > def all_conditions(f,d) > f == 4*d and f+6 == (d+6)*3 > end > > loop do > daughter = rand(father = rand(100)) > if all_conditions(father,daughter) > puts "father: #{father} daughter: #{daughter}" > break > end > end Not exactly the fastest way to do it empirically, why random. d = 0 d += 1 until (f = 4*d) && (f + 6) == (d + 6) * 3 puts "Father is #{f} years old, Daughter is #{d}." -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/