Re: Challenge!
- Subject: [mg936] Re: Challenge!
- From: roth at sunny.mpimf-heidelberg.mpg.de (Arnd Roth)
- Date: Wed, 3 May 1995 00:15:20 -0400
- Apparently-to: mathgroup-send at christensen.cybernetics.net
- Organization: Max-Planck-Institut fuer Medizinische Forschung
In article <3nkc03$mq8 at news0.cybernetics.net> Paul E Howland <PEHOWLAND at taz.dra.hmg.gb> writes: > I have two lists of equal length M. > > I wish to generate a third list also of length M, where the i th element > of this list is either the i th element of the first list, or the i th > element of the second list. > > It should be equally probable that the new element be chosen from the > first or second list. > > eg. I have a list {a,b,c,d,e,f,g} > and another {A,B,C,D,E,F,G} > > valid answers would be: > {a,B,C,d,e,F,G} > {a,b,c,d,E,f,g} > {A,B,C,D,e,f,G} > etc. In[1]:= swap[l1_List, l2_List] := ReleaseHold[Thread[ Hold[If[Random[Integer] == 0, #1, #2] &][l1, l2]]] In[2]:= swap[{a, b, c, d, e, f, g}, {A, B, C, D, E, F, G}] Out[2]= {a, B, C, d, E, f, g} In[3]:= swap[{a, b, c, d, e, f, g}, {A, B, C, D, E, F, G}] Out[3]= {A, B, c, d, e, F, G} Arnd Roth Abteilung Zellphysiologie Max-Planck-Institut fuer Medizinische Forschung Postfach 10 38 20, D-69028 Heidelberg, Germany http://sunny.mpimf-heidelberg.mpg.de/people/roth/ArndRoth.html