MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: combinations problem


On 28.04.2013 06:58, eros olmi wrote:
> Hi
> i want to select 6 combinations from numbers 1 to 49 with condition that its sum equal 152,
 >the following code works but its timing is 157 seconds on windows xp 
mathematica v 8. can we make this timing shorter ?
> Select[Subsets[Range[49],{6}],Total[#]==152&]

Hi, the following should work about 68 times faster:

Select[Map[Union, IntegerPartitions[152, {6}, Range[49]]],
  Length[#] == 6 & ]

cheers,

Michael Taktikos



  • Prev by Date: Re: Mathematica-assisted learning was .. Re: Speak errors
  • Next by Date: question
  • Previous by thread: Re: Mathematica-assisted learning was .. Re: Speak errors
  • Next by thread: question