# Trouble Nesting a function

I have a function that I want to nest the output of into the same function for example I have

p = 47; g = 2; gb = 47;
func[z_, a_, b_] := Which[
Mod[z, 3] == 0, {g*z, a + 1, b},
Mod[z, 3] == 1, {gb*z, a, b + 1},
Mod[z, 3] == 2, {z*z, 2*a, 2*b}];
tort = func[1, 0, 0];
hare = func[func[1, 0, 0]];


Now tort value is tort == {47,0,1} and I wanna reiterate that into my hare variable but i can't figure out how to do it properly

basically feed tort's value into hare and get {13,0,2}

I'm basically trying to implement Pollard Rho for Discrete Log

Use Apply (@@) to replace the head of the List with func.

hare = func @@ tort;


Or equivalently:

hare = Apply[func, tort];


Note however that while func[47,0,1] == func @@ tort, it does not equal {13,0,2}. If that's the expected answer, double check your definitions.

For repeated nesting, such as with Nest, it may be useful to write an anonymous function that wraps that, such as func @@ # &:

Nest[func @@ # &, {1, 0, 0}, 2]


Another way could be to define the function like func[{z_, a_, b_}] := ...