Re:List Hepl Needed
- To: mathgroup at smc.vnet.net
- Subject: [mg5135] Re:[mg5065] List Hepl Needed
- From: Vandemoortele CC Group R&D Center <w.meeussen.vdmcc at vandemoortele.be>
- Date: Wed, 6 Nov 1996 01:32:54 -0500
- Sender: owner-wri-mathgroup at wolfram.com
after reading Todd Garley's and John Fultz'es suggestions, here is a way to decompose the problem into simple steps : Needs["DiscreteMath`Combinatorica`"] ?Partitions Partitions[n] constructs all partitions of integer n in reverse lexicographic order lis=ToExpression[FromCharacterCode/@(64+32+Range[14])] {a, b, c, d, e, f, g, h, i, j, k, l, m, n} For all partitions of 14 elements into 7 sublists : your=Select[Partitions[14],Length[#]==7&] {{8, 1, 1, 1, 1, 1, 1}, {7, 2, 1, 1, 1, 1, 1}, {6, 3, 1, 1, 1, 1, 1}, {6, 2, 2, 1, 1, 1, 1}, {5, 4, 1, 1, 1, 1, 1}, {5, 3, 2, 1, 1, 1, 1}, {5, 2, 2, 2, 1, 1, 1}, {4, 4, 2, 1, 1, 1, 1}, {4, 3, 3, 1, 1, 1, 1}, {4, 3, 2, 2, 1, 1, 1}, {4, 2, 2, 2, 2, 1, 1}, {3, 3, 3, 2, 1, 1, 1}, {3, 3, 2, 2, 2, 1, 1}, {3, 2, 2, 2, 2, 2, 1}, {2, 2, 2, 2, 2, 2, 2}} Up to here, the lists remain small ; further down, they inflate because all permutations have to be taken into account : ?Permutations Permutations[list] generates a list of all possible permutations of the elements in list. Timing[par=Flatten[Permutations/@your,1];] {0.06 Second, Null} Timing[ran=Range[#]&/@par;] {2.494 Second, Null} Timing[try=Map[Rest at FoldList[Last[#1]+#2&,{0},#]&,ran,1];] {2.925 Second, Null} Timing[result=Map[Part[lis,#]&,#]&/@try;] {1.402 Second, Null} Length[result] 1716 ByteCount[result] 370672 as you can see, going from "ran" to "try" costs a lot of trickery, although at first glance it should be easy. nice problem, this ! Wouter. NV Vandemoortele Coordination Center Group R&D Center Prins Albertlaan 79 Postbus 40 B-8870 Izegem Tel: +/32/51/33 21 11 Fax:+32/51/33 21 75 vdmcc at vandemoortele.be