MathGroup Archive 2011

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

Search the Archive

Re: Quick Mathematica Question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115288] Re: Quick Mathematica Question
  • From: "W. Craig Carter" <ccarter at mit.edu>
  • Date: Thu, 6 Jan 2011 02:06:40 -0500 (EST)

Hello Dean,
Does collecting the values into a list work for you:

generateFromRule[init_, generations_,aRule_] :==
  Nest[Flatten[# /. aRule] &, {init}, generations]

e.g.,

theRule == {0 -> 1, 1 -> {1, 0}};


generateFromRule[0, 10,theRule]
generateFromRule[{0, 1, 1}, 10, theRule]

Them if you want the number as in your post
FromDigits[generateFromRule[{0, 1, 1}, 10, {0 -> 1, 1 -> {1, 0}}]]


Note! sometime equal-signs get doubled while posting in the mathgroup, there are no double-equals above.

Craig


On 5 Jan,   2011, at 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.
>
> --
> Dean Rosenthal
>
> cell: 646 733 6966
> www.deanrosenthal.org
> http://www.the-open-space.org/webmag/test1.html


  • Prev by Date: Re: Numerical Solver for 2D/3D (Reaction-)Diffusion equation
  • Next by Date: Re: Quick Mathematica Question
  • Previous by thread: Re: Quick Mathematica Question
  • Next by thread: Re: Quick Mathematica Question