[Question]
  [
A *Munchausen Number* in base \$b\$, also known as a [Perfect digit-to-digit invariant](https://en.wikipedia.org/wiki/Perfect_digit-to-digit_invariant) or PDDI is a peculiar type of positive integer where the sum of its base-\$b\$ digits raised to themselves is equal to the number itself. They are named for the fictional [Baron Munchausen](https://en.wikipedia.org/wiki/Baron_Munchausen), who apparently hoisted himself up via his own ponytail to save himself from drowning. A related concept is [Narcissistic numbers](https://codegolf.stackexchange.com/questions/15244/test-a-number-for-narcissism). 
For instance, \$1\$ is trivially a Munchausen number in every base because \$1^1=1\$. Additionally, every positive integer is a base-1 Munchausen number by definition.
More interestingly, \$3435\$ is a base-10 Munchausen number because \$3^3+4^4+3^3+5^5=3435\$, and in fact is [the only other base-10 Munchausen number](https://arxiv.org/pdf/0911.3038v2.pdf).
A partial list of Munchausen numbers in every base up to 35 can be found on the OEIS as sequence [A166623](https://oeis.org/A166623).
Given a positive integer \$n>0\$, determine if it is a Munchausen number in any base \$b\geq2\$.
## Rules
* Default I/O rules apply, so:
	+ Full program or functions are acceptable.
	+ Input can be from STDIN, as a function argument, and output can be to STDOUT, as a function return value, etc.
* Default loopholes apply.
* The output must be one of two distinct, consistent results. So `TRUE` is fine for truthy and `FALSE` is fine for falsy, but you can reverse that or return `None` for truthy and `1` for falsy or whatever. Please specify the selected results in your answer.
* Your answer has to work at least theoretically for any positive integer.
* Munchausen numbers use the convention \$0^0=1\$, so \$2\$ is a base-2 Munchausen number as \$1^1+0^0=2\$. Your code must follow this convention.
* Explanations are strongly encouraged, even though submissions will most likely use the brute-force search method.
* Using esoteric languages earns you brownie points since Munchausen was apparently a strange person.
## Test Cases
```
Truthy
1 (all bases)
2 (base 2)
5 (base 3)
28 (base 9 and base 25)
29 (base 4)
55 (base 4)
3435 (base 10)
923362 (base 9)
260 (base 128)
257 (base 64 and base 253)
Falsy
3
4
591912
3163
17
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in each language (in bytes) wins!
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 7 bytes
```
LвDmOQZ
```
[Try it online!](https://tio.run/##yy9OTMpM/W9o7HZ4gou9koKunYKS/X@fC5tccv0Do/7rxPw35DLiMuUysuAysuQyBTJMzbmMzAy4jE2MTbmMuUy4jA3NjLkMzQE "05AB1E – Try It Online")
The larger test cases will time out on TIO.
**Explanation**
```
L         # push range [1 ... input]
 в        # convert input to a digit list in each of these bases
  Dm      # raise each digit to the power of itself
    O     # sum each
     Q    # check each for equality with input
      Z   # max
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
bŻ*`§ċ⁸Ị
```
Yields `0` for Munchausen and `1` otherwise.
**[Try it online!](https://tio.run/##y0rNyan8/z/p6G6thEPLj3Q/atzxcHfX////jSwA "Jelly – Try It Online")**  
Or [see the first five hundred positive integers split up](https://tio.run/##ASsA1P9qZWxsef//YsW7KmDCp8SL4oG44buK/8OH4oKsVCxA4bifQMKlUv//NTAw "Jelly – Try It Online") as `[[Munchausen], [non-Munchausen]]`.
### How?
```
bŻ*`§ċ⁸Ị - Link: integer, n
 Ż       - zero-range -> [0,1,2,3,4,...,n]
b        - (n) to base (vectorises)
   `     - with left as both arguments:
  *      -   exponentiation (vectorises)
    §    - sums
     ċ   - count occurrences of:
      ⁸  -   n
       Ị - is insignificant (abs(x) <= 1)
```
---
Alternative for `1` for Munchausen and `0` otherwise:
```
bŻ*`§ċ>1
```
[Answer]
# [J](http://jsoftware.com/), ~~33~~ ~~28~~ 27 bytes
```
e.1#.i.@>:^~@(#.inv ::1)"0]
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/U/UMlfUy9RzsrOLqHDSAzLwyBSsrQ00lg9j/mlypyRn5ChppSgaaCoYKRgqmCkYWCkaWCqamCsYmxqbI0sYKJgqG5grGhmbG/wE "J – Try It Online")
* `e.` is the input an element of...
* `1#.` the sum of each row of...
* `i.@>: ... ]` 0..input and the input itself, passed as left and right args to...
* `^~@(#.inv)"0` convert the right arg (input) to each base in the left arg and raise each result elementwise to itself `^~@`.
* `::1` finally this is needed because you can't convert uniquely to base 1, so it errors. in this case, we simply return 1, which won't match for any number *except* 1, which is what we want
[Answer]
# [R](https://www.r-project.org/), ~~72~~ 69 bytes
-1 byte thanks to digEmAll
```
function(x){for(b in 1+1:x)F=F|!sum((a=x%/%b^(0:log(x,b))%%b)^a)-x;F}
```
[Try it online!](https://tio.run/##JYzRCsIwDEXf/Yr6UEhw4rJs00722s8YrIPKYHYwHRTUb6@6vOTe3JybJfk2@TUMz3EOEPHl5wWcGoOiAzURbWvf@8d6B@jbqE/adZA303yDmDlErR12PR7j1X7SAB4IM@Wh2GYl/iJiJJOQSxZjCuZa8KLORasz4u7/jLe9lKIhQwIy1XKhH5i@ "R – Try It Online")
Outputs `TRUE` for Munchausen numbers and `FALSE` otherwise.
`x%/%b^(0:log(x,b))%%b)` converts `x` to base `b`, and the for loop does the rest of the work (reassigning `F`, which is `FALSE` by default).
We need to allow the base `b` to go all the way to `x+1` instead of `x` to handle the case `x=1`.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 13 bytes
```
õ@ìXÄ x_pZ
øN
```
Saved one byte thanks to @Shaggy
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=9UDsWMQgeF9wWgr4Tg&input=NQ)
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 51 bytes
```
{?grep {$_==sum [Z**] .polymod($^a xx*)xx 2},^$_+2}
```
[Try it online!](https://tio.run/##BcHfCoIwFAfg@99TnIsR/onIc9zMC@k9ihQhlWCmTILJ8NnX962DsybOO51GamK4T25YKaiuabbfTM9Hlr3osi52n5d3otqevM9S74mPc6u6nI84Lo4S@/kOW0oBRFu/05jkqktxxAIMDb6Ba2gNKUWjZhHDYHMF6wqCElIYQVH9AQ "Perl 6 – Try It Online")
### Explanation:
```
{                                                 } # Anonymous code block
 ?grep {                                  }         # Do any
                                           ,^$_+2   # Of the bases from 2 to n+1
            sum                              # Have the sum of
                      .polymod($^a xx*)      # The digits of n in that base
                [Z**]                  xx 2  # Raised to the power of themselves
        $_==                                 # Equal to the original number?
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 50 bytes
TIO timed out on 591912. Somehow edges out Perl by 1 byte... (at time of writing)
```
->n{(2..n+1).any?{|b|n.digits(b).sum{|d|d**d}==n}}
```
[Try it online!](https://tio.run/##BcFBDoIwEADA@76CAAfA0NhdCnIAH6KGSBpIDxZiy4G0/bp15nvMZ1yGZ6xH7QpkTF94yd76vDs/e82kWpU1xVwyc3ycl15WlQzDoEOI@2FNkmb5NCaZWx75xOw2qVdIIwcEAXgD7EEIoIYE9EjUImB7BRQdEDRAvCXgHfy23apNm1jrPw "Ruby – Try It Online")
[Answer]
# JavaScript (ES7), 60 bytes
Returns a Boolean value.
```
n=>(F=b=>(g=n=>n&&g(n/b|0)+(n%=b)**n)(n)==n||b<n&&F(b+1))(2)
```
[Try it online!](https://tio.run/##hdBLbsIwEAbgPafIpskMUcnDITQS7jIn6A5Y2DSkRdYEYahUKXdPnQaF1K5aLyzr96cZj4/iQ@j9@f10eaTmteoOvCP@DCWXZq@5OZPv10CRbGMMgR64xPmcEAg5p7aVa3NfggwTREix2zekG1UtVFNDsHk5Xy9vn7sAZ9P8AAZ73yuKPBBKeVLoStsqnapeeKlNlg5hTpWnmxlJ4ZDCJpnTaPkvYRkb0EiS2DZFyljez/XHY/J4aHUvY0aY/VDBljalUPqXr2VoJ5mTsCR3WbJC7L4A "JavaScript (Node.js) – Try It Online")
### Commented
```
n =>                   // n = input
  ( F = b =>           // F = recursive function taking a base b
    ( g = n =>         //   g = recursive function taking an integer n
      n &&             //     if n is not equal to 0:
        g(n / b | 0) + //       do a recursive call with floor(n / b)
        (n %= b) ** n  //       and add (n mod b) ** (n mod b)
    )(n)               //   initial call to g with the original value of n
    == n ||            //   return true if the result is equal to n
    b < n &&           //   otherwise, if b is less than n:
      F(b + 1)         //     try with b + 1
  )(2)                 // initial call to F with b = 2
```
[Answer]
# [APL (dzaima/APL)](https://github.com/dzaima/APL), ~~23~~ 13 bytes
```
⊢∊⊂+.*⍨⍤⊤⍨¨2…
```
[Try it online!](https://tio.run/##SyzI0U2pSszMTfyf9qhtgsb/R12LHnV0Pepq0tbTetS74lHvkkddS4CMQyuMHjUs@6/J9ahvKlBh2qEVhgpGCqYKRhYKRpYKpqYKxibGQJ6ZgYKRqTlCkbGCiYKxoZmxgqH5fwA "APL (dzaima/APL) – Try It Online")
Thanks to Adám, ngn and dzaima, we managed to shave 10 bytes off this answer by using dzaima/APL.
Prefix tacit function. Munchausen numbers return 1, else 0.
### How
```
⊢∊⊂+.*⍨⍤⊤⍨¨2… ⍝ Prefix tacit function, argument will be called ⍵
             2… ⍝ Generate the integer sequence [2..⍵]
          ⊤⍨¨  ⍝ Convert ⍵ to each base in the vector
     +.*⍨⍤      ⍝ Raise each digit of each element in the vector to itself, then sum
⊢∊⊂            ⍝ Check if ⍵ is in the resulting vector.
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 65 bytes
```
#<2||!Tr[Check[#^#,1]&/@#~IntegerDigits~i]~Table~{i,2,#}~FreeQ~#&
```
[Try it online!](https://tio.run/##FctBC4IwFMDxzxIPPL2obU4LKoQi6JbgTQyWPOaj9LDWSd1XX3b8w@/fG99Rbzy3JtpjhIOcplXl6nNH7auGB6Bokk0B4TZ4suQubNl/AjehMs83hZFRIszh6ojKAEm8Ox58UX6ZfA3rky3g/49iYRrlDuUetUaVqqWyLUqdo8IUlcgUinyO8Qc "Wolfram Language (Mathematica) – Try It Online")
*-4 bytes from @attinat*
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 17 bytes
```
Ｎθ¬Φθ⁼θΣＥ↨θ⁺²ιＸλλ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/98zr6C0xK80Nym1SKNQ05oroCgzr0TDL79Ewy0zpwQkqKPgWliamFMMYgWX5mr4JhZoOCUWp4L4ATmlxRpGOgqZmppATn45UH2OjkKOJgRY//9vZGr@X7csBwA "Charcoal – Try It Online") Link is to verbose version of code. My 16-byte attempt didn't work but that might be a bug in Charcoal, so watch this space. Outputs `-` unless the number is a Munchausen number. Explanation:
```
Ｎθ                  Input `n` as a number
   Φθ               Try bases `2` .. `n+1`
       Σ            Sum of
         ↨θ         `n` converted to base
           ⁺²ι      Next trial base
        Ｅ           Each digit
              Ｘλλ   Raised to its own power
     ⁼              Equals
      θ             `n`
  ¬                 Logical Not
```
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 99 bytes
```
n=>Enumerable.Range(2,n).Any(x=>{int g=0,t=n;for(;t>0;t/=x)g+=(int)Math.Pow(t%x,t%x);return g==n;})
```
[Try it online!](https://tio.run/##hdDNS8MwFADw@/6KMBASrP1KVy0xBQ/upCAieJge0pJ2hfoKSYod4t9e45hzTREDubz83kdeqS9K3YzrHsrrBoxXdF2bV3wEnt9C/yaVKFrpPwqoJY49IP4N7PDA8w@LUc1Dz3BgVacwM3nITMAHUp9zbF/JvTBb/6F7x@Zs8OwlTEnTK7BpNueTjGzxrBoj7xqQeLl5Ur3Z7l6X5DRc4YgQhvYnCBAWbYsKoaUmExRP0DdA8VSs5oI6Na5@yFFkjshmInG6rP4TNKEHcxRROCVZTGm6/9Gfg6Thoc9vETv@4nSfL7BZi1bPF0qJE0jcAI3SGYoubWT8Ag "C# (Visual C# Interactive Compiler) – Try It Online")
[Answer]
## Haskell, 61 bytes
```
_#0=0
b#n|m<-mod n b=m^m+b#div n b
f n=elem n$1:map(#n)[2..n]
```
Returns `True` for Munchausen and `False` otherwise.
[Try it online!](https://tio.run/##ZcvBCoJAEIDhu08xsB6KJnFn3DWjfRKxUFSSnFEqOvXuW507/vD91/ZxG@Y5xovJQ550Rt9y2svSg0IX5Cy7zvTT61fJCBqGeRDQ1B6lXTdGtzVlmTZR2kkhQL8kAOt90iek8BUwQm2R0CEdkCp0DrlghxUxe0LyOZIrm/@JsUC2ntGWTfwA "Haskell – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/) `-lm`, ~~79~~ 75 bytes
```
f(n,b,i,g,c){for(g=b=1;b+++~n;g*=!!c)for(c=i=n;c-=pow(i%b,i%b),i/=b;);n=g;}
```
[Try it online!](https://tio.run/##LU7daoMwGL3PU9iCkNQjNUnjJlmeZOtFTZvwQRtLFQYT9@hzuvXunMP582X0fp4DT2hBiPBiDN2DR9c6aduiKL6TjTu32Xix6t6RS9aX7t59csqXTN4K0N61Vtjkop3m24kSFyOjNGTDpR/696MbmYSCgXqFamAM9EEbNErrWkHVFZR5AdM4wDSykQpa1hpy0SbL1t21jFxl6a2nr0sX@F@z2D9ZJSwVhWDZ/bE4A9/m9TnLzx9pi/8LdMQzs0AhLJsYm398uJ5iP5fX2y8 "C (gcc) – Try It Online")
Returns `0` for Munchausen numbers, and `1` otherwise.
---
### also 75 bytes
```
a,b;f(n){for(a=b=1;b+++~n;a*=g(n)!=n);n=a;}g(n){n=n?g(n/b)+pow(n%b,n%b):0;}
```
[Try it online!](https://tio.run/##LU5dS8MwFH3Pr6iDQq65Y02yVOs1@EN0D0m3lMCWjrUgWOpPt6a6hwvn6x5Ou@3adlkcego8wRT6G3fWW0leCPGdyD3aLhsPNgEl62he2ZRsestg50Fc@0@eSo/54KWiebm4mDhMLKaxGE/DOLwf7MQkKjSonlE1aAzqvTbYKK1rhaquUJknZBr3aBrZSIVa1hpl1mZi66a1LNqK4usQv0594H/NsLuzCigKAay43nIy8E1ZH4vy@JE2@D8hHvD@kyEAsZmx5acNZ9cNy/Z8@QU "C (gcc) – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), ~~83~~ 81 bytes
```
def f(n,b=2):
 s=0;m=n
 while m:k=m%b;s+=k**k;m/=b
 return s==n or b<n>0<f(n,b+1)
```
[Try it online!](https://tio.run/##dYztCoMgFIb/exXCGGSNLbWP9eEups2RlBpqjK7eRSzszw4ceF7Oe55pcb1WxAs5aeOgXSxY92q5M/w5Gyu0GoUULsLpNsi/@Bu@I3XpGEE1gJaljWQKwE8vRg5lPTB57hqbsCGOh0beWAeg4W42au0yBbWBXaseabtJEoz8ZIRyqxMjsCO5H7hIQ6AZzUOqCKUF@VMlefkL4TtcMwROO@cVrvBBQ3FxaOIS@S8 "Python 2 – Try It Online")
Returns `1` for truthy and `0` for falsey. Because of the recursion, can't practically deal with `591912`, but it works in the abstract.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~66~~ 65 bytes
```
{$^a==1||[+] map {$a==[+] map {$_**$_},$a.polymod($_ xx*)},2..$a}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJZm@79aJS7R1tawpiZaO1YhN7FAoVoFyEdw4rW0VOJrdVQS9Qrycypz81M0VOIVKiq0NGt1jPT0VBJr/1tzpeUXKRjq6RkbKOjaKagkKlRzcRYnViooAZlAgeo0oFitkjVX7X8A "Perl 6 – Try It Online")
[Answer]
# JavaScript (ES6), 88 bytes
```
f=n=>{for(b=2;n-b++;){for(c=0,r=n;r;r=(r-a)/b)c+=(a=(r%b))**a;if(n==c)return 1}return 0}
```
[Answer]
# [Icon](https://github.com/gtownsend/icon), 109 bytes
```
procedure m(n)
every k:=2to n&{i:=n;s:=0
while{a:=i%k;a<:=1;s+:=a^a;0<(i/:=k)}
n=s&return 1}
return n=1|0
end
```
[Try it online!](https://tio.run/##bY7RCsIwDEWf7VdEQWlx4Lrq1M58iSgUV7BMM@mmIuq3a1BBH0zI5ULIuQmbmh6PQ6w3vjxGD3tJSviTjxeoLGZtDTS4BotUNBZTcd6Gnb86i6FfFW5hURfN0KJbuyJdyDCyWKm7IGwG0bfHSKDv4uMI9S0VnsrfNBdIKgFc78xzDK1v5F52lzqBLIEJ64xnzpa9GRvWeWZMzsssT1km05VKoMf9Jr0YUnX@Y00CY@bonI3@XnZenz0B "Icon – Try It Online")
Times out for `591912`. [Icon](https://github.com/gtownsend/icon) treats `0^0` as an overflow and that's why I need an additional check for zero.
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 15 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
╡!←!║╝âñoêû►╦ä▓
```
[Run and debug it](https://staxlang.xyz/#p=b5211b21babc83a46f889610cb84b2&i=1%0A2%0A5%0A28%0A29%0A55%0A3435%0A260%0A257%0A%0A3%0A4%0A3163%0A17&a=1&m=2)
Takes very long for the larger test cases.
Explanation:
```
{^xs|E{c|*m|+x=m|a Full program, unpacked
                   Implicitly input x
{              m   Map over bases [1 .. x]
 ^                   Increment base (effectively mapping over [2 .. x+1])
  xs                 Tuck x below base
    |E               Get digits of x in base
      {   m          Map over digits:
       c|*             copy and power
           |+        Sum
             x=      sum = x?
                |a Check if any element in array is true
                   Implicit output
```
]