Re: Quick Mathematica Question
- To: mathgroup at smc.vnet.net
- Subject: [mg115289] Re: Quick Mathematica Question
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Thu, 6 Jan 2011 02:06:53 -0500 (EST)
f1[x_] := ToExpression[StringReplace[
IntegerString[x], {"0" -> "1", "1" -> "10"}]];
f2[x_] := ToExpression[StringJoin[ToString /@
(IntegerDigits[x] /. {0 -> 1, 1 -> 10})]];
NestList[f1, 0, 5]
{0, 1, 10, 101, 10110, 10110101}
NestList[f1, 0, 20] == NestList[f2, 0, 20]
True
Bob Hanlon
---- Dean <deanrosenthal at gmail.com> 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