Re:Puzzle

*Subject*: [mg2611] Re:[mg2258] Puzzle*From*: penny at edu-suu-scf.sc.suu.edu (Des Penny)*Date*: Mon, 27 Nov 1995 21:36:16 -0500*Approved*: usenet@wri.com*Distribution*: local*Newsgroups*: wri.mathgroup*Organization*: Wolfram Research, Inc.

>Here's a nice puzzle. Find the four numbers in the following sequence >which total 100: {6, 44, 30, 15, 24, 12, 33, 23, 18}. It would seem that >there might be a nice way to do this with Mathematica. Any takers? >Will Self >Billings, Montana Hi MathGroupers: This is my first posting to the group. I was catching up on my MathGroup messages over the last few days and came up with a different approach to the above problem. While not as elegant as some of the other methods presented, it does have the merit of finding the solution if you allow the numbers to be chosen more than once: IN: set={6, 44, 30, 15, 24, 12, 33, 23, 18}; spam=Outer[List,set,set,set,set]; (* Gives all possible combinations of 4 numbers from set *) spam=Flatten[spam,3]; spam=Map[Sort[#]&,spam]; (* This allows the Union to remove duplicates *) Length[spam] OUT:6561 (* It's big!! *) IN: spam=Union[spam]; Length[spam] OUT:495 IN: Cases[spam,x_ /;(Apply[Plus,x]==100)] OUT: {{6, 6, 44, 44}, {15, 18, 23, 44}, {23, 23, 24, 30}} Thanks to Allan Hayes and Scott Herod for showing me how to apply Monty Python to Mma. Cheers, Des Penny ========================== Des Penny Physical Science Dept. Southern Utah University Cedar City, UT 84720 VOICE: (801) 586-7708 FAX: (801) 865-8051 e-mail: penny at suu.edu ==========================