Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Re: combinations problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg130718] Re: combinations problem
  • From: totarefugium <mtaktikos at t-online.de>
  • Date: Mon, 6 May 2013 02:26:53 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <klia8o$s8q$1@smc.vnet.net>

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