[Date Index]
[Thread Index]
[Author Index]
Re: permutations?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg46492] Re: permutations?
*From*: Paul Abbott <paul at physics.uwa.edu.au>
*Date*: Fri, 20 Feb 2004 06:53:40 -0500 (EST)
*Organization*: The University of Western Australia
*References*: <c11sc1$n64$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
In article <c11sc1$n64$1 at smc.vnet.net>,
sean_incali at yahoo.com (sean kim) wrote:
> let's say you have...
>
> a, b, c, d, e and...
>
> a', b', c', d', e'
>
> what are the possible combination will go from a( or a' ) to e ( or
> e')
>
> so that you get...
>
> {a b c d e}, {a b c d e'}, {a b c d' e}, {a b c d' e'}, {a b c' d e},
> { a b c' d' e}, {a, b, c' d e'}, {a, b, c' d' e'}....so on
>
> I have 32 from doing it the brute force way by hand. how do i do that
> with Mathematica?
There are, of course, many ways. If l1 and l2 are your two (equal
length) lists then
Flatten /@ Distribute[{{#[[1]]},{#[[2]]}} & /@
Transpose[{l1, l2}], List, List]
does the trick. I find Distribute rather subtle and expect that there
might be a better way to do this using Distribute.
Another way that computes all the lists (using Boolean logic) is
List @@@ List @@ LogicalExpand[ And @@ Or @@@ (l1 + l2)]
However, this does not preserve the ordering you want and an application
of Sort is required.
A third way is to recognise the "binary" nature of your problem: the
position of the changing element corresponds to the binary sequence 0,
1, 10, 11, 100, 101, 110, 111, etc.
With[{n = Length[l1]}, (l2 # + (1 - #) l1 & ) /@
(PadLeft[IntegerDigits[#, 2], n] & ) /@ Range[0, 2^n - 1]]
> also... what kinda problem is described above?
Well, how did _you_ encounter the problem? Often this will suggest a
good approach to solving it.
You might find "Computational Recreations in Mathematica" by Ilan Vardi
interesting.
Cheers,
Paul
--
Paul Abbott Phone: +61 8 9380 2734
School of Physics, M013 Fax: +61 8 9380 1014
The University of Western Australia (CRICOS Provider No 00126G)
35 Stirling Highway
Crawley WA 6009 mailto:paul at physics.uwa.edu.au
AUSTRALIA http://physics.uwa.edu.au/~paul
Prev by Date:
**Re: Computing sets of equivalences**
Next by Date:
**Simple Question [Clearing Variables]**
Previous by thread:
**RE: permutations?**
Next by thread:
**bug in integration with version 5.0 ?**
| |