Python, 7070 71 bytes
p=lambda f,n:n>9and-~p(f,(i:=lambda n:n>9and f(i(n//10),n%10)orif n>9else n)(n))
Attempt This Online!Attempt This Online!
Takes in an anonymous function f
and an integer n
.
+1 bytes from @xnor for noticing an error when n=0
in i
.
Python, 65 bytes
p=lambda f,n:~-len(n)and-~p(f,reduce(f,n))
from functools import*
Takes in an anonymous function f
and a string n
representing an integer.
Python 2, 42 bytes
p=lambda f,n:~-len(n)and-~p(f,reduce(f,n))
Same as above. Posted based on the recommendation of @tsh.