Re: Terras inverse
- To: mathgroup at smc.vnet.net
- Subject: [mg43769] Re: [mg43471] Terras inverse
- From: Omega Consulting <info at omegaconsultinggroup.com>
- Date: Fri, 3 Oct 2003 02:28:54 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
At 07:00 AM 9/17/2003, Gino Prosapio wrote:
>I'm looking for a fast algorithm of inverse Terras/Collatz function (i.e.
>f(m)={(2m-1)/3 (if integer), 2m}). This program should return the list:
>
>{1},{2},{4},{8},{5,16},{3,10,32},{6,20,21,24},{12,13,40,42,128}... etc.
>
>That correspond to the tree
>
>
> 1
> |
> 2
> |
> 4
> |
> 8
> / \
> / \
> / \
> 5 16
> / \ \
> 3 10 32
> \ \ / \
> 6 20 21 64
> ... ................. .
>
>
>Thank you.
Looks like a problem for Nest.
f[{m_, old_}] := Module[{new},
new = Flatten[{Cases[(2 m - 1)/3, _Integer], 2 m}];
{Complement[new, old], Union[new, old]}
]
First /@ NestList[f, {{1}, {1}}, 7]
{{1}, {2}, {4}, {8}, {5, 16}, {3, 10, 32}, {6, 20, 21, 64}, {12, 13, 40, 42,
128}}
--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"
http://omegaconsultinggroup.com