Hi,

My son is in third grade and came home with a math word problem the other day.

The basic problem said something like

"Ted has $6.00 to spend. How many combinations can he buy if

Ice pops: $.40

Candy: $.25

Toy: $.30

We answered it by trial and error, but I was thinking there must be a way to solve this to find all the possible result sets.

I know how to solve systems of equations but in this case it would only be one equation

40x + 25y + 30z = 600

Any ideas how to solve this for all possible (interger) result sets? My algebra is rusty, it's been a while since I've been in grade school.

I'm working on it myself now in perl, but wanted to see what everyone else came up with.

Nacht

In this case, the most efficient program would not be the simplest.

The simplest program here would be a brute force search.

For numbers this small, brute force search is still very fast, and a simple approach, like

perl -le 'for($x=0;$x<=600;$x+=40){

would seems to be more efficient use of programmer time.

If you are interested, we could develop a more sophisticated perl program based on Bézout's identity, but this may be beyond the understanding of most 3rd graders.