Re: Quick Mathematica Question

• To: mathgroup at smc.vnet.net
• Subject: [mg115293] Re: Quick Mathematica Question
• From: Murray Eisenberg <murray at math.umass.edu>
• Date: Thu, 6 Jan 2011 02:07:40 -0500 (EST)

```It's unclear exactly what types of objects you want here: strings
consisting of "0" and "1"; actual lists of digits 0 and 1; or integers
whose digits are 0 and 1.

If strings, the following will do what you want:

stringstep[str_] := StringReplace[str, {"0" -> "1", "1" -> "10"}]
NestList[stringstep, "0", 8]

If lists of binary digits:

bitstep[lis_] := Flatten@Replace[lis, {0 -> 1, 1 -> {1, 0}}, 1]
NestList[bitstep, {0}, 8]

If integers with digits 0 and 1, you could start with either of the
above and then just convert the strings or binary lists into integers.
Thus if you assign the last output to, say, bitList, then:

FromDigits /@ bitList

If you want your results to be displayed, as you showed, on separate
lines, then just use ColumnForm on your output.

On 1/5/2011 5:46 AM, Dean wrote:
> How would I program user-defined rules such as
>
> 0->1
> 1->10
>
> to give the output, and specify the number of recursions.  For example,
> starting with 0,
>
> 0
> 1
> 10
> 101
> 10110
> ...
>
> Specified, 5 generations.

--
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

```

• Prev by Date: Re: Quick Mathematica Question
• Next by Date: Re: Quick Mathematica Question
• Previous by thread: Re: Quick Mathematica Question
• Next by thread: Re: Quick Mathematica Question