MathGroup Archive 2001

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

Search the Archive

Re: Re: list of bits to string

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28741] Re: [mg28719] Re: [mg28688] list of bits to string
  • From: BobHanlon at aol.com
  • Date: Fri, 11 May 2001 03:38:57 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

If all you need are the strings, then change the definition of gCode:

gCode[1] = {{"0"},{"1"}} ;

gCode[n_Integer?Positive] := With[{g=gCode[n-1]}, 
      Join["0"<>#&/@g,"1"<>#&/@Reverse[g]]];

gCode[4]

{"0000", "0001", "0011", "0010", 
  "0110", "0111", "0101", "0100", 
  "1100", "1101", "1111", "1110", 
  "1010", "1011", "1001", "1000"}


Bob Hanlon

In a message dated 2001/5/10 8:55:08 AM, murraye at mediaone.net writes:

>Thank you all for suggesting the same solution that I came up with after
>sending my original inquiry.  In my situation, I actually had a list of
>such lists of binary digits (arising, in fact, as the Gray code of order
>4):
>
>   gCode[1] = { {0}, {1} } ;
>   gCode[n_] := With[{g = gCode[n - 1]}, 
>      Join[Map[Prepend[#, 0] &, g], Map[Prepend[#, 1] &, Reverse[g]]]]
>
>So to convert the result of gCode[4] to the list of 4-character strings
>I needed (to label the vertices in a Hamiltonian circuit of the "4-cube"
>graph), I used:
>
>   Map[Apply[StringJoin, Map[ToString, #]] &, gCode[4]]
>
>The preceding expression still seems overly complicated to me: did I
>miss some simplification?
>


  • Prev by Date: Re: Plotting
  • Next by Date: Re: Plotting
  • Previous by thread: Re: list of bits to string
  • Next by thread: List of bits to String