In looking for something entirely different I came across the following problem :

The product of the ages of David' s children is the square of the sum of their ages. David has less than eight children. None of his children have the same age. None of his children is more than 14 years old. All of his children is at least two years old. How many children does David have, and what are their ages?.

The first paragraph was the one which caught my attention. Its Diophantine restriction compelled me to try Mathematica to find out if it was as involved as the solution claimed (yes, I peeked). Its coding was totally straightforward. Although brute - force, it worked, and worked fast. And it was amenable to be used in the classroom.

Flatten[Table[

Select[Subsets[Range[2, 14], {n}], Total[#]^2 == Times @@ # &], {n,2, 7}], 1]

{{2, 4, 6, 12}}

So, David has four children with ages listed in the above result. How do we know that those ages were going to be different? We considered the generation of all subsets in the range of ages allowed; each of those subsets is, by definition, formed by different elements. There are only 8192 of them. We just select those that comply with the algebraic condition and it turned out to be only one answer. This answer would not be unique if we allow 1 - year olders :

Flatten[Table[

Select[Subsets[Range[1, 14], {n}], Total[#]^2 == Times @@ # &], {n,2, 7}], 1]

{{2, 4, 6, 12}, {1, 2, 4, 7, 14}, {1, 2, 4, 8, 9}}

A somewhat more satisfying unique solution might be that one in which the solution would use the minimum and maximal possible ages; but mentioning that fact could be perceived as giving away too much information, and lower the appeal of the problem. We can devise more complex algebraic requirements exemplifying David ' s numerous family :

Flatten[Table[

Select[Subsets[Range[1, 20], {n}], Total[#]^3 == Times @@ # &], {n,2, 7}], 1]

{{2, 4, 9, 10, 15, 20}, {2, 5, 6, 12, 15, 20}, {3, 4, 5, 10, 18, 20}, {1, 2, 5, 8, 9, 15, 20}, {1, 3, 4, 5, 12, 15, 20}}

Of course the bottleneck in this type of problems would be the exponential generation of subsets. If we need to illustrate what to do then to students (as is my case), we need to look for other kind of examples in which the memory limitations call for another approach. On the other hand, it is nice to be able to solve casual little gems like this one from time to time.