[Question]
  [
A [narcissistic number](https://en.wikipedia.org/wiki/Narcissistic_number) is a natural number which is equal to the sum of its digits when each digit is taken to the power of the number digits. For example \$8208 = 8^4 + 2^4 + 0^4 + 8^4\$, so is narcissistic.
We'll define a function \$f(x)\$ as the following, for a natural number \$x = d\_1d\_2\dots d\_n\$, where \$d\_i\$ is a single digit \$0\$ to \$9\$ (therefore \$x\$ has \$n\$ digits):
$$f(x) = \sum\_{i=1}^nd\_i^n$$
In this case, a number is narcissistic if \$f(x) = x\$.
However, when we apply \$f(x)\$ to a number repeatedly, we find an interesting pattern emerges. For any given \$x\$, the sequence either reaches a fixed point (i.e. a narcissistic number), or enters a fixed loop which repeats infinitely. For examples, take the three integers \$x = 104, 127, 370\$:
* \$x = 104\$: Repeated application of \$f(x)\$ leads to the following chain
$$104, 65, 61, 37, 58, 89, 145, 190, 730, 370, 370, ...$$
Here, the loop eventually reaches a fixed point, \$370\$.
* \$x = 127\$: Repeated application of \$f(x)\$ leads to
$$127, 352, 160, 217, 352, 160, 217, ...$$
Here, the triple \$352, 160, 217\$ repeats ad infinitum
* \$x = 370\$: \$x\$ here is already narcissistic, so the chain will just be an endless stream of \$370\$s.
These examples document the two possible outcomes for a given \$x\$. By treating a fixed point as a loop of length \$1\$, we now arrive at the task at hand:
Given a natural number \$n > 0\$, output the length of the loop that arises through repeated application of \$f(n)\$.
The above three examples return \$1\$, \$3\$ and \$1\$ respectively. You can assume that all \$n\$ eventually enter a loop, which appears to be the case for at least all \$n < 10^4\$. If there exists an \$n\$ for which this is false, your program may do anything short of [summoning Cthulhu](https://codegolf.stackexchange.com/questions/128784/find-the-highest-unique-digit/214724#comment317467_128784).
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest code in bytes wins.
The vast majority of numbers return \$1\$. However, these two arrays contain all \$n < 1000\$ which don't, along with what their outputs should be:
```
[ 59,  95, 106, 115, 127, 136, 138, 147, 149, 151, 157, 159, 160, 163, 168, 169, 172, 174, 175, 177, 178, 179, 183, 186, 187, 189, 194, 195, 196, 197, 198, 199, 217, 228, 229, 235, 238, 244, 245, 253, 254, 255, 258, 259, 267, 268, 271, 276, 277, 279, 282, 283, 285, 286, 289, 292, 295, 297, 298, 299, 309, 316, 318, 325, 328, 335, 352, 353, 355, 357, 358, 361, 366, 367, 369, 375, 376, 381, 382, 385, 388, 389, 390, 396, 398, 405, 408, 417, 419, 424, 425, 442, 445, 447, 450, 452, 454, 456, 457, 459, 465, 466, 468, 469, 471, 474, 475, 477, 478, 479, 480, 486, 487, 488, 491, 495, 496, 497, 499, 504, 507, 508, 511, 517, 519, 523, 524, 525, 528, 529, 532, 533, 535, 537, 538, 540, 542, 544, 546, 547, 549, 552, 553, 555, 556, 558, 559, 564, 565, 567, 568, 570, 571, 573, 574, 576, 580, 582, 583, 585, 586, 589, 591, 592, 594, 595, 598, 601, 607, 609, 610, 613, 618, 619, 627, 628, 631, 636, 637, 639, 645, 646, 648, 649, 654, 655, 657, 658, 663, 664, 666, 669, 670, 672, 673, 675, 678, 679, 681, 682, 684, 685, 687, 689, 690, 691, 693, 694, 696, 697, 698, 699, 705, 706, 708, 712, 714, 715, 717, 718, 719, 721, 726, 727, 729, 735, 736, 741, 744, 745, 747, 748, 749, 750, 751, 753, 754, 756, 760, 762, 763, 765, 768, 769, 771, 772, 774, 777, 778, 779, 780, 781, 784, 786, 787, 788, 791, 792, 794, 796, 797, 799, 804, 805, 807, 813, 816, 817, 819, 822, 823, 825, 826, 829, 831, 832, 835, 838, 839, 840, 846, 847, 848, 850, 852, 853, 855, 856, 859, 861, 862, 864, 865, 867, 869, 870, 871, 874, 876, 877, 878, 883, 884, 887, 891, 892, 893, 895, 896, 900, 903, 906, 914, 915, 916, 917, 918, 919, 922, 925, 927, 928, 929, 930, 936, 938, 941, 945, 946, 947, 949, 951, 952, 954, 955, 958, 960, 961, 963, 964, 966, 967, 968, 969, 971, 972, 974, 976, 977, 979, 981, 982, 983, 985, 986, 991, 992, 994, 996, 997, 999]
[  3,   3,   3,   3,   3,   2,  10,  14,  10,   3,  10,  14,   3,   2,  14,  10,   3,  14,  10,   2,  10,   2,  10,  14,  10,  10,  10,  14,  10,   2,  10,  10,   3,  10,   3,   3,   3,   2,   2,   3,   2,  10,  10,  10,  14,  10,   3,  14,  10,  14,  10,   3,  10,  10,  10,   3,  10,  14,  10,  10,  14,   2,  10,   3,   3,   2,   3,   2,  10,  10,  10,   2,  10,  10,  14,  10,  10,  10,   3,  10,  14,   6,  14,  14,   6,  10,  14,  14,  10,   2,   2,   2,   3,  14,  10,   2,   3,  10,   3,  10,  10,  10,  14,  10,  14,  14,   3,  14,  10,  10,  14,  14,  10,  10,  10,  10,  10,  10,  10,  10,  14,  10,   3,  10,  14,   3,   2,  10,  10,  10,   3,   2,  10,  10,  10,  10,   2,   3,  10,   3,  10,  10,  10,  10,  10,  14,   3,  10,  10,  14,  10,  14,  10,  10,   3,  14,  10,  10,  10,  14,  10,  10,  14,  10,  10,   3,  10,   3,   3,  10,   3,   2,  14,  10,  14,  10,   2,  10,  10,  14,  10,  10,  14,  10,  10,  10,  14,  10,  10,  10,  14,  10,   3,  14,  10,  14,   2,  10,  14,  10,  14,  10,   2,   6,  10,  10,  14,  10,  10,  10,   6,   2,  14,   3,  14,   3,  14,  10,   2,  10,   2,   3,  14,  10,  14,  10,  10,  14,  14,   3,  14,  10,  10,  14,  10,  10,   3,  14,   3,  14,  10,  14,   2,  10,   2,  10,  14,   6,  14,  14,  14,  10,  10,   2,  14,  14,   2,  14,  10,  10,  14,   3,  14,  10,  14,  10,  14,  10,  10,  10,   3,  10,  10,  10,  10,   3,  10,  14,   6,  14,  14,  10,  10,  10,  10,  10,  14,  10,  10,  14,  10,  14,  10,   2,   6,  14,  10,  10,   2,  14,  14,  14,  10,  14,  10,  10,   6,  10,   6,  14,  14,  10,  10,  14,  10,   2,  10,  10,   3,  10,  14,  10,  10,  14,  14,   6,  10,  10,  10,  10,  10,  14,  10,  10,   3,  10,  10,  10,  14,  10,  10,  10,   6,   2,   2,  14,  10,  10,  14,   3,  10,  10,   6,  10,   6,  10,  10,  10,   2,   3,  2]
```
Furthermore, [this](https://tio.run/##y0rNyan8/99Fy0cl@FjXsTVc1ofbH@5cdbjd59gm60cNc2tg/GNdmu7///83NDAAAA) is a program which takes an integer \$n\$ and, for each integer \$1 \le i \le n\$, generates it's output and the loop that arises.
[This](https://math.stackexchange.com/q/3896749/427632) is a question over on Math.SE about whether the output ever exceeds \$14\$, and if each natural number will eventually go into a loop or not.
  
[Answer]
# [Haskell](https://www.haskell.org/), 85 bytes
```
l=length
k?x|elem x k=l$x:takeWhile(/=x)k|q<-show x=(x:k)?sum[read[k]^l q|k<-q]
([]?)
```
[Try it online!](https://tio.run/##BcGxDsIgEADQvV/B0AGGRuum6YXPcCCYkHgVcgdKwcjAv@N73hVC5jEYGNOr@ol068gYRRMEPFdHePeBUZ6gKep5W4p//0QD2W6kdPlGc6B7GrIPFrnTtmQ77SCN1WpEFxJ8jpDqvIt1vZ4v4w8 "Haskell – Try It Online")
This is frustratingly long for Haskell. We have one main function here. It keeps track of a list `k` of numbers we already visited, appending new numbers to the front. Once we reach a number `x` which is on our list we return one more than the largest prefix not containing `x`.
```
k ? x
  | elem x k
  =
    length (x : takeWhile (/=x) k)
  | otherwise
  =
    (x : k) ? sum [ read [x] ^ length (show x) | k <- show x ]
```
[Answer]
# [Python 3](https://docs.python.org/3/), ~~107~~ \$\cdots\$ ~~90~~ 84 bytes
Saved a byte thanks to [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)!!!
```
f=lambda n,l=[]:n in l and-~l.index(n)or f(str(sum(int(d)**len(n)for d in n)),[n]+l)
```
[Try it online!](https://tio.run/##dZbdbttGEIXv9RRsbiymjMH9nRkDKtAn6E3vXCNwLToRQlOGKKNJDffV3Y/6s0QriY@0HM7unHNmRPDxx/rrsguvr/ez9vbh7/lt0VXt7PrmqisWXdEWt93803/t5aKbN9@nXblcFffTfr2a9k8P00W3ns7Ljx/bpuPWPffmw6auL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cbGn6SeqVgf9o0p1Ccu1WNXRj7vq8X3vXi/6@z6qCF@zMTvjDzdl7cFw7Fd/qAzvqv9ztQ3iePiftTHQ7bfXfmTk0bl3g3Ez8bjbCvPaR@XHxXKu484PsL/bKgPs3mufDjfp7wZ35Huk/rHg@ZvJsPbWD977q6aYnhZ66pmeF37d/E43b6nVftnQPkyufva3H1rVrPpxV9PXuLdRbVZuHBRTm7b9vOX5XI@@3P11Ew2Rw0HrW67L83UVYWra1deTQr@9bPt6yLvhJvrZrYhwethsbjfbtvWLpq2bwq3SXpcDW@W9xfP3Uvx6bfiuX8pnnd8rvvZrLl5udiediCyXwyvq8WQMuH0ffDq6NAPv7dtseiLf5q2/aW4KsvyQzkZSp8k/bF87Kuif1o17Y@iXz40xcOiX99@ay4vL4ur6Yfy9X8 "Python 3 – Try It Online")
Expects input as a string.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 bytes
I wonder if this is the same as caird's answer (it probably isn't, because the control flow here almost certainly can be simplified by anyone who actually *knows* Jelly, or perhaps even by a good lossless compression utility). This may also be wrong.
```
D*L$S
ÇÐLÇƬL
```
[Try it online!](https://tio.run/##y0rNyan8/99Fy0clmOtw@@EJPofbj63x@f//v6GpJQA "Jelly – Try It Online")
[Answer]
# [Raku](http://raku.org/), ~~67~~ ~~65~~ 64 bytes
```
{{$_-1-.first(:k,.tail)}($_,{sum .comb X**.chars}...{%\{$_}++})}
```
[Try it online!](https://tio.run/##DYvLCoMwFER/ZRBbfAZvfVRL9Tu6KIgVQ6WKJbELCfn29C4OcxhmvpNaKrceOEu0zhi/TykVclZ6D26fROzDvIQ28PvE6N8KMW7rC48oEuN7UNoKIczpyS8bxza0Tg8HPL9H28FIcO1Bbgr3skFTgrIKRJyXKyhnz2tQwV40oJIYdp5SlTE5U3fuDw "Perl 6 – Try It Online")
* `$_, { ... } ... { ... }` generates the sequence of numbers, starting with `$_`, the argument to the outer function. The first braces enclose the function that generates successive elements, and the second braces enclose the function that indicates when to stop.
* `sum .comb X** .chars` produces the next number from the preceding one. The `comb` method with no arguments splits strings/numbers into their characters/digits. The `chars` method returns the number of characters/digits in a string/number. The list of digits is cross-exponentiated with the number of digits by the `X**` operator, then summed.
* The ending condition uses an anonymous state hash variable `%`, which stores the number of times each element has been seen so far. The iteration stops when the current number has been seen for a second time.
* That sequence is fed into an inner anonymous function, which is called immediately. (This is a bit shorter than storing the sequence into a variable.) Just like the outer function, this inner function accepts its argument in the `$_` variable.
* `.first(:k, .tail)` finds the index (thanks to the `:k` adverb) of the first element of the sequence which is equal to the final element, returned by `.tail`.
* `$_ - 1 - .first(...)` is the length of the sequence, minus one, minus the first index of the single repeated element, giving the length of the final cycle.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~78~~ 73 bytes
-5 thanks to J42161217. His answer is better, so check that out too.
```
#[]//.a_@e___/;a!=e:>a~Tr[#^#2&@@RealDigits@a]~e/.a_@e__:>{e}~Position~a&
```
[Try it online!](https://tio.run/##Ncq9CsMgEADgPW9RAplsjR0TFIcs3ULpdlzlKGoP8gOJW4ivbqd@8zdT@vqZEn@oBF1qQClv5Kx3zsmeLtp3hvJrg/pd3xtrn56mgSOn3RJm/7@dOfyZx3XnxOuSqSnDClXUwXJfPQJEACUUolFi3HhJwFcTEStxsFBt255Yfg "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 12 bytes
```
LUṠ-U¡λṁ^L¹d
```
[Try it online!](https://tio.run/##AR8A4P9odXNr//9MVeG5oC1VwqHOu@G5gV5Mwrlk////MTM4 "Husk – Try It Online")
Found a better way to do it by removing the longest unique prefix from the infinite list, and taking the longest unique prefix of that.
# [Husk](https://github.com/barbuz/Husk), 14 bytes
```
▼mLUmUṫ¡λṁ^L¹d
```
[Try it online!](https://tio.run/##ASMA3P9odXNr///ilrxtTFVtVeG5q8KhzrvhuYFeTMK5ZP///zEzOA "Husk – Try It Online")
Basically, we make an infinite list of infinite lists in order to find which one contains the required cycle. Then we take the length of the cycle.
## Explanation
```
▼mLUmUṫ¡λṁ^L¹d
       ¡λ      apply the following to get an infinite list
             d take the digits
          ^L¹  the the power of their length
         ṁ     sum them
      ṫ        get the postfixes of the list
    mU         get the logest unique prefix of each postfix
   U           get the longest unique prefix of that
 mL            Map each cycle to it's lenght
▼              take the minimum  
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~202~~ ... 149 bytes
```
f(l){long a[16]={},i,k=l,n;for(;i=k;a[n++&15]=k){for(l=0;k;k/=10)l++;for(;i;i/=10)k+=__builtin_powi(i%10,l);for(l=16;l--;)if(a[l]==k)return n-l&15;}}
```
[Try it online!](https://tio.run/##LY3BbsIwEETP4Su2SKls2RH2oRy6@EtCFIVQo5W3DoqCOET@9mDTnmZ35s3u2NzGcdu8YLnyFG8wtPbYuTVp0sGxjuinWSC5gEMblfq0X50Lci0uO4MBw8FZI1mpfxLpbQTl@v7yIF4o9vfpSYJqazRL/KvaI3LToCQvhpY7l4/OP8tjjhAbzl8wpY3iAr8DRSFh3VWlVxwCBxaznLIaY/Ko1JuoSsw59oIklt2DYPjInMxbdZ8z4MW@vn5DfT3HvQbSwAVNu7S9AA "C (gcc) – Try It Online")
## Explained
```
f(l) {
    long a[16] = {}, // Circular buffer of recently seen values
         i,          // Current value, will be initialized to l,
                     //  l will become number of digits in i,
                     //  and will later be used as a loop counter
         k = l,      // Will become f(i)
         n;          // Current index into the circular buffer
    for (; i = k;                     // Loop forever, let i = f(i)
                  a[n++ & 15] = k) {  // Store f(i) in the buffer
        for (l = 0; k; k /= 10)       // Set length to zero, loop over all digits in k (which is equal to i)
            l++;                      // Increment l for each digit
                                      // k is zero after this loop
        for (; i; i /= 10)            // Loop over all digits again
            k += __builtin_powi(i % 10, l); // Add pow(digit, length) to k
        for (l = 16; l--;)            // Check all the values in the buffer
            if (a[l] == k)            // If k matches a value in the buffer
                return n - l & 15;    // Return the distance between k and the match in the buffer
    }
}
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~70~~ 59 bytes
```
Gather@NestList[Tr[#^#2&@@RealDigits@#]&,#,#]~Count~{_,__}&
```
[Try it online!](https://tio.run/##FcfBCsIwDADQjwn0VLHz7ggoeBGR6a3UEkaoha1Cm52G@/WI7/ZmkjfPJHkkTUe9/Fvxxk2uuYl/Vg8vOBjEgWk655SlIQRjwULYTp@lyLZGG@PX6L3mIh52ffIQgtnjgycexQ9UEmPnnLMJoe9MUP0B "Wolfram Language (Mathematica) – Try It Online")
-11 bytes from @att
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 27 bytes
```
ＮθＷ¬№υθ«⊞υθ≔ΣＸ↨θχＬθθ»Ｉ⊕⌕⮌υθ
```
[Try it online!](https://tio.run/##Jc3NCoMwEATgs3mKHHfBQoVCD55aoSAUkfYJUl1MQDc1P3ooffbU4nFgvplOK9dZNaZU8zuGJk4vcjBjKVZtRpLQ2ACVjRwg5nJGRPkRWRu93nMpsov3ZmB4xglau276qjzBnMviiLm8Ew9Bw1/u/a9ondnmKuUD1Nw5mogD9XAz3MODFnIbj7i/YZlScTqnwzL@AA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｎθ
```
Input `n`.
```
Ｗ¬№υθ«
```
Repeat until a loop is detected.
```
⊞υθ
```
Save the previous value.
```
≔ΣＸ↨θχＬθθ
```
Compute the next value.
```
»Ｉ⊕⌕⮌υθ
```
Output the number of terms in the loop.
[Answer]
# JavaScript (ES7), 72 bytes
Expects the input number as a string.
```
n=>(g=i=>i-g[[...n].map(d=>t+=d**n.length,t=0)|t]||g(-~i,g[n=t+'']=i))``
```
[Try it online!](https://tio.run/##FcxNDoIwEAXgvafowsRWoaEiKDHDzhO4JCQ0/NQanBJo3IheHZnNl3nJe/PUbz3Vox18iK5plw4WhJwbsJDb0BSFlBJL@dIDbyD3B2j2e5R9i8Y/Ag@RmH05z4aHPxuYAsEfdrsSrBBVtVwLlmQBy5KAqShdUXQdzysxxfiycqJ4WmsqUQRFWqk0ImKCeil9yrJyIzs33nT94MggZ7XDyfWt7J3hlebbD34FA7b9dByld3c/WjRciG8lxPIH "JavaScript (Node.js) – Try It Online")
### Commented
```
n => (                   // n = input number as a string
  g = i =>               // g is a recursive function taking a counter i
    i -                  // subtract from i
    g[                   // lookup in g:
      [...n].map(d =>    //   for each digit d in n:
        t +=             //     add to t:
          d ** n.length, //       d raised to the power of the length of n
        t = 0            //     starting with t = 0
      ) | t              //   end of map(); yield t
    ]                    // end of lookup in g
    ||                   // if the above result is NaN,
    g(                   // do a recursive call:
      -~i,               //   pass i + 1
      g[n = t + ''] = i  //   copy t to n, coerced back to a string
                         //   and set this entry to i in g
    )                    // end of recursive call
)``                      // initial call to g with i zero'ish
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 27 bytes
```
{tgjlᵗgᵗz^ᵐ+}ᵃ↖N{¬≠&}↔a↰₄bl
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFSu9qhtw6Ompoe7Omsfbp3wv7okPSvn4dbp6UBcFQcU0QYKNz9qm@ZXfWjNo84FarWP2qYkgvW0JOX8/x@tYGigo2BqqaOgYGmqA@SYAQlDEMvIHEgYg7jGFkDCBMQ1AaozNDUEESCuqWUsAA "Brachylog – Try It Online")
```
{tgjlᵗgᵗz^ᵐ+}ᵃ↖N{¬≠&}↔a↰₄bl
{           }ᵃ↖N            repeat the predicate N times
                             and accumulate results
 tg                         last result as list [x]
   jlᵗgᵗ                    [x, [len(x)]]
        z^ᵐ                 each digit ^ length
           +                sum
                {¬≠&}       must have duplicates (not all are different)
                     ↔a     reverse and take prefixes (shortest first)
                       ↰₄   that must have duplicates
                         bl length - 1
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 19 bytes
```
`XIvIFYAtn^syy-]=Pf
```
[Try it online!](https://tio.run/##y00syfn/PyHCs8zTLdKxJC@uuLJSN9Y2IO3/f0MTcwA "MATL – Try It Online") Or [plot the sequence](https://matl.suever.net/?code=vXJx%22%40%0A%60XIvIFYAtn%5Esyy-%5D%3DPf%0AJwhXJx%5D%0AGJ3%243YH&inputs=50%3A170&version=22.3.0) from `50` to `170` (it takes about 30 seconds).
### Explanation
```
`         % Do...while
  XI      %   Copy into clipboard I. This implicitly takes input the first time
  v       %   Concatenate stack contents vertically. This attaches the newly computed 
          %   term onto the sequence. The first time it does nothing
  I       %   Paste from clipboard I. This pushes the last computed term
  FYA     %   Convert number to vector of decimal digits
  tn^s    %   Duplicate, number of elements, element-wise power, sum. This computes a
          %   new term to extend the sequence
  yy      %   Duplicate top two elements in the stack: sequence so far and new term
  -       %   Element-wise difference. This is truthy if all values are nonzero
]         % End. A new iteration is run if top of the stack is truthy
=         % (The stack contains the computed sequence and a new term that has been
          % found to appears in that sequence) Element-wise equality comparison
P         % Reverse
f         % index of true value. Implicitly display
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 11 bytes
```
D*L$SƊƬ⁺€ṪL
```
[Try it online!](https://tio.run/##y0rNyan8/99Fy0cl@FjXsTWPGnc9alrzcOcqn/@H24GsyP//FUwtdRQULE11FAwNzICEIYhlZA4kjEFcYwsgYQLimgDVGZoagggQF6TN0MwARBiDCJA6M5CYuRGIMAERIKPMQYrNQbLmQFkjoAYjoBlGRgA "Jelly – Try It Online")
```
D              Take the decimal digits
 *             to the power of
  L            the length of
   $           the list of decimal digits
    S          and sum them.
     Ɗ         For all that,
      Ƭ        iterate until a loop is reached collecting all intermediate results,
        €      then for each of the collected results
       ⁺       iterate again starting from there,
         Ṫ     take the results from the last result,
          L    and get the length of that.
```
Can be even shorter if we take input as a digit list:
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
*LSDƲƬ⁺€ṪL
```
[Try it online!](https://tio.run/##y0rNyan8/1/LJ9jl2KZjax417nrUtObhzlU@/10Ot6sA2ZH//yuYWuooKFia6igYGpgBCUMQy8gcSBiDuMYWQMIExDUBqjM0NQQRIC5Im6GZAYgwBhEgdWYgMXMjEGECIkBGmYMUm4NkzYGyRkANRkAzjIwA "Jelly – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 11 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
Turns out I got the same as [Unrelated String](https://codegolf.stackexchange.com/a/214872/53748).
```
D*L$SƊƬ⁺€ṪL
```
A monadic Link accepting a positive integer which yields a positive integer.
**[Try it online!](https://tio.run/##ASAA3/9qZWxsef//RCpMJFPGisas4oG64oKs4bmqTP///zE1OQ "Jelly – Try It Online")**
### How?
```
D*L$SƊƬ⁺€ṪL - Link: n
      Ƭ     - collect while distinct:
     Ɗ      -   last three links as a monad:
D           -     digits
   $        -     last two links as a monad:
  L         -       length
 *          -       exponentiate
    S       -     sum
        €   - for each:
       ⁺    -   repeat the last link (the collect-while-distinct, above)
         Ṫ  - tail (this will be a single loop)
          L - length
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 15 bytes
```
Δ¤SDgmO©ªÙ}R®k>
```
[Try it online!](https://tio.run/##ASQA2/9vc2FiaWX//86UwqRTRGdtT8KpwqrDmX1Swq5rPv//WzE2OF0 "05AB1E – Try It Online")
Takes input as a singleton list containing the integer.
A different approach that comes in at 16 bytes:
```
λSDgmO}ηíεćk}Ù¥н
```
[Try it online!](https://tio.run/##ASQA2/9vc2FiaWX//867U0RnbU99zrfDrc61xIdrfcOZwqXQvf//NTk "05AB1E – Try It Online")
**Commented**:
```
Δ¤SDgmO©ªÙ}R®k>   # implicit input: [x]
Δ         }       # run until the output does not change:
 ¤                #   take the last integer from the list
  S               #   split into digits
   D              #   duplicate
    g             #   take the length of the copy
     m            #   take each digit to the power of the length
      O           #   sum all powers
       ©          #   store this value in the register
        ª         #   and append it to the list
         Ù        #   uniquify the list
                  #   the loop only stops if Ù removed the new element,
                  #   which only happens if it was in the list already
           R      # reverse the (unique) list
            ®     # take the last computed value
             k    # find the 0-based index in the list
              >   # and increment it
λSDgmO}ηíεćk}Ù¥н  # implicit input: x
λ     }           # recursively apply the code to the input
                  #   to generate an infinite list
 SDgmO            # same as above
       η          # take the prefixes
        í         # reverse each prefix
         ε  }     # map over the reversed prefixed
          ć       #   extract the first element 
           k      #   find its index in the remaining prefix
                  #   this returns -1 if the prefix was unique
                  # this results in [-1, ..., -1, res-1, res-1, ...]
             Ù    # uniquify => [-1, res-1]
                  # while this list is finite, 05ab1e does not know this
              ¥   # take the differences => [(res-1) - (-1)] = [res]
               н  # take the first element => res
```
[Answer]
# [APL (dzaima/APL)](https://github.com/dzaima/APL), ~~30~~ 29 bytes
```
{1⊃⍸⌽(⊢/=⊢){+/(⊢*≢)10⊤⍵}⍡⍵⊢⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pSszMTfz/qG@qp/@jtgkG/9OAZLXho67mR707HvXs1XjUtUjfFkhoVmvrgzhajzoXaRoaPOpa8qh3a@2j3oVACigM4oBMAepOUzC1/A8A "APL (dzaima/APL) – Try It Online")
-1 byte using `⎕IO←0`.
Since the length of the cycle never exceeds \$n\$, we can loop n times instead of finding a fixed point, then calculate the length of the cycle.
## Explanation
```
{⊃⍸1↓⌽(⊢/=⊢){+/(⊢*≢)10⊤⍵}⍡⍵⊢⍵}
                          ⊢⍵  input integer n
            {          }⍡⍵    apply the following n times, collecting intermediate results:
                    10⊤⍵       get base 10 digits
                (⊢*≢)          raise to the power of length
             +/                and sum
      (⊢/=⊢)                  bit mask of the locations of the last element
   1↓⌽                        reverse and remove first 1
 ⊃⍸                           first index of the last element
```
[Answer]
# [Icon](https://github.com/gtownsend/icon), 99 bytes
```
procedure f(n)
t:=table()
i:=1
until\t[n]do{t[n]:=i
(s:=0)+:=!n^*n&\z
n:=s
i+:=1}
return i-t[n]
end
```
[Try it online!](https://tio.run/##VY/fqsIwDMbv8xSxF9J6NmhVGBTqi/gH1HUQmKnU7hyO4rNrpwPddxPy/ZIvhI6BH49zDEdfd9FjI1lBsi7tD62XCsg6Ax0najdpzds63PpiHYG8WKfVj3UT3s14urkCW3cByo65Q/Spi4xU9uPguf66cdoT52jM@ouUvDR6WQgsVyiKpm/UCM6rLzivRnBR6Q/MzQiKcpB4u/7Xx3/sP8IU0GitsQ54e7GsRpJaGZwO21SIIZeG1Du8HnkC "Icon – Try It Online")
[Answer]
# [Red](http://www.red-lang.org), 125 bytes
```
func[n][m: copy #()i: 1	while[not m/:n][put m n i i: i + 1 s: 0
foreach d k: to""n[s:(-48 + d)**(length? k)+ s]n: s]i - m/:n]
```
[Try it online!](https://tio.run/##PYzLCoMwFAXX9SsOduMDqbaC5W76D90GF8UkNag3EiOlX58GCm4OAzMcp2R4Kin6RFPQOw@Ce7EQBrt@cc5yQ2hOn9HMSrD1WC4U/bpHAsMgaoMSDTZCnWjr1GsYITERvE1TFhtlVXuPicyLIpsVv/34wJSX2HqmOAbV/zWszrCHRlO3ycHX7uBbV4cf "Red – Try It Online")
[Answer]
# Scala, 117 bytes
Port of Wheat Wizard's [Haskell answer](https://codegolf.stackexchange.com/a/214864/95792).
```
def>(n:Any,k:Seq[_]=Nil):Any=if(k toSet n)1+k.indexOf(n)else>(s"$n".map(d=>math.pow(d-48,s"$n".size).toInt).sum,n+:k)
```
[Try it online!](https://scastie.scala-lang.org/rGFG3DIiRHKsmkj23VvCdw)
# Scala, 160 bytes
```
Stream.iterate(_){n=>s"$n".map(d=>math.pow(d-48,s"$n".size).toInt).sum}.scanLeft(Seq[Int]())(_:+_).flatMap(_.tails).find(l=>l.size>1&&l.head==l.last).get.size-1
```
[Try it online!](https://scastie.scala-lang.org/ysthakur/yMNczRpGSYunrPUN9CFq4A/64)
A ridiculously long solution, made worse by the fact that Scala doesn't have `**` like Python and other languages do, and `inits` returns the biggest inits first, so we have to use `scanLeft(Seq[Int]())(_:+_)`.
[Answer]
# [R](https://www.r-project.org/), 84 bytes
```
x=scan();while(!(y=match(x,F,0))){F=c(x,F);x=sum((x%/%10^((z=nchar(x)):0)%%10)^z)};y
```
[Try it online!](https://tio.run/##rY5BasMwEEX3OsWUYJgBk0p0U2yUZU7QXUlATGUsKktGkqmdkLM79iI36PJ//ue9tK6zzmwCUvvXO2/xDRc9mMI9zvW5lkR0P2veA7XbdBoQ5@q9UvKKeNOBe5NwJmokVVtJ1xs92mVVH59CHODHdi5YMBm6KXBxMUCJwL3lXxgmX9zoLRSbC7DJNjciDfi1kUQwiX2Mo379NsZd/KOheOx@xnvYUS5nl4tj2JkZTgq6mCCAC6CORyVlI9DobMbRL6iarZD1S5Ho25zUZX0C "R – Try It Online")
**Commented:**
```
x=scan();                               # get input as x
                                        # F is vector that holds values of f(x) so far
                                        # (initialized by default as zero)
while(!(y=match(x,F,0))){               # if x is present in F, get its matching index as y, 
                                        # otherwise set y to zero.  
                                        # While !y (x not present in F yet):
 F=c(x,F);                              # prepend F with x
 x=sum((x%/%10^((z=nchar(x)):0)%%10)^z) # update x as f(x): 
                                        # sum of decimal digits to the power of # digits
};
y                                       # We exit the while loop when F contains x;
                                        # at this point, y gives the index, which is the 
                                        # loop length
```
[Answer]
# [J](http://jsoftware.com/), 40 bytes
*-5 by FrownyFrog!*
```
0(i.~~:@|.)(,*/@~:$1#.&(^#)10#.inv{:)^:_
```
[Try it online!](https://tio.run/##lZRNj9xEEIbv@ytaWZTMoInpr/oyQopA4hRx4BopHFBWCQe4cSHav774cRCz67U9k8O8mnZVt@upt9p/PLwYXt2lH8b0Kp1STuP0ez2kn359@/NDPnwa7u/HN5@H4@H07Xdv7sdvyu3w8vD@9ljy7fDpz7//GY/vx98ejje//Dikd@PtcP9uvB9fDp@Hw2kt9TCfwp6bmw@/f/wrHb6/O6bS7b/V4e5FPiaJU0ohp1SyTlL4V22SxrL5iR3IlFekICzZVjQjDSFPeWYV6QhHGclG1Ig6yc7JTsB5FiTPFQSBIBDsiClay7Ss1RGWTRCWvSMspSEsZV4Spb6q7KW0agVRhGfUUr0i7HW2UVWloBoEKKhSS6WWSi0tI0WR6VmrgvCPqppUpCHz0hCiWhC2UVCjTY3mNApqTpRaGmU0ZwdltMgIKVTQsyD8oyW9TCm9doRAr8j8j6hkhGf0pYsic4BtSh4FdZrTKajToY5vndI6ber41ulVd86jQx3fOkX2YAdt6hTZ6VWnTZI7YsiUJ6UgLKlZakNIoXChf4K10ipClHZKYwdOS88IUTyXrghRZlKgFNoutF1AFdouoIqyA16h9wKvGOfBK8Y2oAUrBErBCmEsBD/E5wBHwSvMhjCxArngjOaCGDLlaclIQ4gCrdwoBVUbydwtBVAbUXxTsLSTApbim0Kk@KYQKVdNIVLMU3xTYJRLp8Ao5im@Kb4pw6UQqbMNIsVBhUiZMAVLg71gKV4qXurMhqHG6BmfB8NQKxXpCAGstTIHSK4FIRlow1rDUAPaOlFsNKANGw1oA9oYW@MjYxhq9MAw1PjSmPJeemAYanhp9MDw0uiB4aUxu0YPjB4YrhqNMHpgGGr0wJhiA99w1cA38A18g9wZZQff8ddx1fkAeJmXpNSKEGCeHXIH2nHaGWoH3xllx25nnh27HXwH3yF3Rtkhd4x3yJ0pdr4gDr7jvoPvzLOD74yA0wMH3xllpwdOD5xRdsgdaIfX4XU8d6bYgY6ckYawxN/A3yjz0hBHplcG0AFvYHIw2QF0NE7B6YA3sDtwOuANeAOnA5MD3sDkgDeY8cDpgDdwOuANpj3gDZ1TOADewPMAOoAOoAPPA7uDuQ/wg7kPjA/wA/zA7pjJsTsijun1mKbstCrTlsTNTjTmy785cH72KG@Rcl7W5//O0UeysmPxyrX6vkh7vm218L5LlDcoF@c9IlrUslXG8lm/@Mqk/@edl/nJs/PJi0Yso20PddmSvtKrlfdeI1cMzUoPVm28FiY/f9E2at6ajbzn/v5gLjn6xfHef8c112Vlslev2mIs9PJM6hOO84v2r/jmVbt6zFac2adc8C5uz/LQ@rSMunXPNzn27@/XXOwrbs81Nu4Cbs@9Pv3X9967@VXe9le/AvDCt2llJi/4tkm59VWpD/8C "J – Try It Online")
### [J](http://jsoftware.com/), 45 bytes
```
[:#.~[:~:&.|.(,1#.&(^#)10#.inv{:)^:(*/@~:)^:_
```
[Try it online!](https://tio.run/##lZRNj9RGEIbv/AqLlWAGD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@MveJ8Ql@gp/YnRM5dmfmfnh9GsbsYVHGLQM3e6Ax3/9NgfOzB3mzlPOyPf13jj6QhR2zVy7V9136022LhcsmUVmhnJ33gGhWy1oZ82dy8ZWD/Z93XpZHz84nzxoxj/Yt1HlLZKFXC@@9Rq4YmoUeLNp4LUx5@qJ11LI2G2XL/e3BnHPIxfHefsc112Vhshev2mws7PJM2iOO84u2r/jqVbt6zBac2aac8c5uz/zQ9riMtnbPVzm27@/PXOwrbs81Nm4Crs@9Pf4nW@9d/Sqv@2s/AXjh27Qwkxd8W6Vc@6q0@/8A "J – Try It Online")
* `…^:_` until result does not change:
* `…^:(*/@~:)` if there is no duplicate in the list:
* `10#.inv{:` digits of the last number …
* `1#.&(^#)` powered by their length, summed
* `,` appended to the list.
* `[:~:&.|.` reverse list, get a bitmask of first occurrences in it, reverse back.
So `1 2 3 2 3 -> 3 2 3 2 1 -> 1 1 0 0 1 -> 1 0 0 1 1`.
* `[:#.~` count the trailing 1s with mixed base conversion.
[Answer]
# [K (Kona)](https://github.com/kevinlawler/kona), 42 bytes
```
--/&{x=*|x}{x~?x}{x,_+/{x^'#x}10_vs*|x}/,:
```
[Try it online!](https://tio.run/##y9bNzs9L/P8/zUpXV1@tusJWq6aitrqizh5E6sRr61dXxKkrV9QaGsSXFYPk9HWs/qcpGBqYcAFJI3MgaWxuAGIbW/wHAA "K (Kona) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
D*L$SƊÐḶL
```
[Try it online!](https://tio.run/##lZW9bhxVFMdf5RZUyMXcj/NVIBrKVKFEKSwz0pqsbBN2A@kiGiQqHgAkHoAaItpIvIf9ImZ@Eylrj2dmN81fe@ece@f8zv/c2e/67fbN/f1Xnz/77Ov/fn3/2@27v5/dv//l7ue/vrj99890@@6fdPf29@f7q7Tb9GnTb2/6V2l7efUyXb8efvXnF5t0eXWz352li01/8TL9eLnbpP77/fn2cvcm7a7Hff1PN/3Frv82Xe93Q@4PZ@l8u027V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2i3NRrfm/vpgTjna0fFef8cp12Vmsmev2mQs9PhM6iOOw4vWr/jiVTt5zGacWaec8E5uz/TQ8riMsnTPFznW7@@nXOwTbs8pNq4CLs@9Pv7V1t67@FVe9lc/AfDIt2lmJo/4tki59FUpL/4H "Jelly – Try It Online")
I always wondered why `ÐḶ` and `ÐĿ` both existed until [this](https://codegolf.stackexchange.com/a/145780/66833) answer made the exact functionality of `ÐḶ` clear.
## How it works
```
D*L$SƊÐḶL - Main link. Takes an integer n on the left
     Ɗ    - Group the previous 3 links into a monad f(n):
D         -   Convert n to digits, D
   $      -   Group the previous 2 links into a monad g(D):
  L       -     Get the length of D
 *        -     Raise each digit to the power of that length
    S     -   Sum
      ÐḶ  - Repeatedly apply f(n) until a value is repeated. Then, apply f(n)
            to that value until it loops, and return the loop formed
        L - Take the length of the loop
```
]