On 7/16/07, Boyko Bantchev <[EMAIL PROTECTED]> wrote:
On 7/15/07, June Kim <[EMAIL PROTECTED]> wrote:
> I've recently seen an interesting puzzle. I know the answer but you
> may enjoy solving it (even with J):
>
> The hostess at her 20th wedding anniversary party tells you that the
> youngest of her three children likes her to pose this problem, and proceeds
> to explain: "I normally ask guests to determine the ages of my three children,
> given the sum and product of their ages. Since Smith missed the
> problem tonight and Jones missed it at the party two years ago, I'll let you
> off the hook." Your response is "No need to tell me more, their ages are ... "
5 6 16.
Perhaps I should have mentioned that, being a bit better versed
in Haskell than in J, I solved it in that language (no doubt a good
solution in J is also possible). Here is the script, the solution being
stored in sol:
equating p x y = p x == p y
comparing p x y = compare (p x) (p y)
triset n = [((a,b,c),(a+b+c,a*b*c)) |
a<-[1..n], b<-[a+1..n+1], c<-[b..n+1]]
set' ts = groupBy (equating snd) (sortBy (comparing snd) ts)
set ts = map fst $ concat $ filter ((>1).length) ts
sol = intersect (set $ set' $ triset 18)
(map (\(a,b,c) -> (a+2,b+2,c+2))
(set $ set' $ triset 16))
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm