Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

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

Search the Archive

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


  • Prev by Date: Re: how can I do this functionally?
  • Next by Date: Re: Error in graphical display
  • Previous by thread: Re: Re: how can I do this functionally?
  • Next by thread: Re: Challenge!