```On Sep 5, 1:34=A0am, "Eric I." <rubytrain... / gmail.com> wrote:
> On Sep 4, 9:40=A0pm, RichardOnRails
>
>
>
> <RichardDummyMailbox58... / uscomputergurus.com> wrote:
> > Hi All,
>
> > My middle-school granddaughter posed the following challenge to me:
>
> > Within 10 minutes, Use the digits 3 to 7 in any order
> > to form a three-digit multiplicand and a two-digit multiplier
> > such that their product is minimal.
>
> > Out of curiosity as to whether my guess was right,
> > and with a view toward eliciting an interest in her
> > for Ruby programming, =A0I wrote the program posted athttp://www.pastie=
.org/266447
>
> > The program reveals that I was wrong, but it took me about 40 lines of
> > code,
> > ignoring comments. =A0That would probably overwhelm her. =A0I was hopin=
g
> > that
> > the code could be condensed with Ruby-isms. =A0BTW, I left some put=92s=
in
> > there
> > intended to give her a sense of the programs functionality.
>
> > Any ideas/suggestions?
>
> Here's one solution that requires the 'permutation' gem:
>
> =3D=3D=3D=3D
>
> require 'rubygems'
> require 'permutation'
>
> perm =3D Permutation.for((3..7).to_a)
>
> min_product =3D 10**5
> min_values =3D nil
>
> perm.map do |p|
> =A0 a =3D p.project
> =A0 v1 =3D a[0, 3].to_s.to_i
> =A0 v2 =3D a[3, 2].to_s.to_i
> =A0 product =3D v1 * v2
> =A0 if product < min_product
> =A0 =A0 min_product =3D product
> =A0 =A0 min_values =3D [v1, v2]
> =A0 end
> end
>
> puts "#{min_values.first} * #{min_values.last} =3D #{min_product}"
>
> =3D=3D=3D=3D
>
> Eric
>
> =3D=3D=3D=3D
>
> Are you interested in on-site Ruby or Ruby on Rails training
> that uses well-designed, real-world, hands-on exercises?http://LearnRuby.=
co

Thanks, Eric,

I should have thought of looking for that.  I certainly know I was
analyzing 5! permutations.

My granddaughter is much more likely to delve into that a little
ways.  I doesn't look so intimidating :-)

Best wishes,
Richard

```