[Question]
  [
A [Narcissistic Number](https://en.wikipedia.org/wiki/Narcissistic_number) is a number which is the sum of its own digits, each raised to the power of the number of digits.
For example, take \$153\$ (3 digits):
> 
> \$1^3 + 5^3 + 3^3 = 153\$
> 
> 
> 
\$1634\$:
> 
> \$1^4 + 6^4 + 3^4 + 4^4 = 1634 = 1 + 1296 + 81 + 256 = 1634\$
> 
> 
> 
**The Challenge:**
Your code must take input from the user and output True or False depending upon whether the given number is a Narcissistic Number.
Error checking for text strings or other invalid inputs is not required. 1 or 0 for the output is acceptable. Code that simply generates a list of Narcissistic Numbers, or checks the user input against a hardcoded list, does not qualify.
[**OEIS A005188**](https://oeis.org/A005188)
  
[Answer]
## APL (15)
```
∆≡⍕+/(⍎¨∆)*⍴∆←⍞
```
Outputs `1` if true and `0` if false.
Explanation:
* `∆←⍞`: read a line (as characters), store in `∆`
* `(⍎¨∆)*⍴∆`: evaluate each character in `∆` and raise it to the power `⍴∆`
* `∆≡⍕+/`: see if the input equals the string representation of the sum of these
[Answer]
### GolfScript, 16 characters
```
~.`:s{48-s,?-}/!
```
Input must be given on STDIN, output is 0 or 1 indicating non-narcissistic / narcissistic number.
Explanation of the code:
```
~              # Evaluate the input to get a number
.              # Accumulator (initially the number itself)
`:s            # Convert number to string and assign to variable s
{              # Loop over characters of the string
  48-          # Reduce character value by 48
  s,           # Push length of input number
  ?            # Power
  -            # Subtract result from accumulator
}/
!              # Not! (i.e. iff accumulator was zero it was a narcissistic number)
```
[Answer]
# Mathematica, 43 chars
```
Tr[#^Length@#&@IntegerDigits@#]==#&@Input[]
```
[Answer]
## Perl, 38 characters
```
perl -lpe '$@=y///c;$s+=$_**$@for/./g;$_=$_==$s'
```
A pretty straightforward implementation.
Here's a slightly different version that fits in 35 characters: 
```
perl -lpe '$@=y///c;$s+=$_**$@for/./g;$_-=$s'
```
This version outputs a *false* value if the input is narcissistic, otherwise it outputs a (Perl-accepted) true value. One might argue that this backwards version falls within the limits of the challenge description, but upon reflection I decided not to. I'm not that desperate to improve my score. Yet.
[Answer]
# J, 23 chars
```
(".=+/@("."0^#))(1!:1)1
```
`(1!:1)1` is keyboard input (returning a string).
`".` converts input to a number; `"0` specifies a rank (dimension) of 0, in other words, taking each character and converting it to a number.
`^` is the power function and `#` is the length function, thus taking each digit to the power of the length of the string (equivalently, the number of digits).
`+/` is just sum, and `=` is comparing the sum and number.
[Answer]
# Ruby, 34+5=39
With command-line flags
```
ruby -nlaF|
```
Run
```
p eval [$F,0]*"**#{~/$/}+"+"==#$_"
```
Outputs true or false.
[Answer]
## R, ~~71~~ ~~69~~ ~~66~~ ~~56~~ 48
Reduced by 8 bytes thanks to [@Giuseppe](https://codegolf.stackexchange.com/users/67312/giuseppe)! The idea was to perform the integer division before the modulo operation.
```
i=nchar(a<-scan()):0;a==sum((a%/%10^i%%10)^i[1])
```
**(3-year) old version with corresponding explanation:**
```
i=nchar(a<-scan()):1;a==sum(((a%%10^i)%/%10^(i-1))^i[1])
```
`a<-scan()` takes a number (integer, real,...) as input (say `153` for the example).  
`i` becomes a vector containing 3 to 1 (the number of characters of `a` being 3).  
`%%` is vectorized so `a%%10^i` means `a` modulo 1000, 100 and 10: it therefore gives `153, 53, 3`.  
`(a%%10^i)%/%10^(i-1)` is the integer division of that vector by 100, 10, 1: therefore, `1, 5, 3`.  
We elevate that with the first element of `i` which is the number of characters (here digits) of `a`, i. e. `3`, thus giving a vector containing `1, 125, 27` that we `sum` and compares to `a`.
[Answer]
# Python 3, 56 bytes
Not very obfuscated, but a simple solution.
```
s = input()
print(int(s)==sum(int(c)**len(s)for c in s))
```
[Answer]
## PHP, ~~80~~ ~~74~~ 66 chars
Very straightforward PHP solution:
```
<?for(;$i<$l=strlen($a=$argv[1]);)$s+=pow($a[$i++],$l);echo$s==$a;
```
It assumes `error_reporting` doesn't include notices, otherwise quite a few extra characters will be needed to initialize `$s=0;` and `$i=0`.
Thx @manatwork for shortening many chars.
[Answer]
# Dc: 48 characters
```
[1pq]Sr?d0rdZSz[d10/r10%lz^rSh+Lhd0!=c]dScx+=r0p
```
Sample run:
```
bash-4.1$ dc -e '[1pq]Sr?d0rdZSz[d10/r10%lz^rSh+Lhd0!=c]dScx+=r0p' <<< '153'
1
bash-4.1$ dc -e '[1pq]Sr?d0rdZSz[d10/r10%lz^rSh+Lhd0!=c]dScx+=r0p' <<< '1634'
1
bash-4.1$ dc -e '[1pq]Sr?d0rdZSz[d10/r10%lz^rSh+Lhd0!=c]dScx+=r0p' <<< '2013'
0
```
[Answer]
# K, 24 23
```
{x=+/xexp["I"$'a]@#a:$x}
```
Shaved 1 char with reordering
```
{x=+/{x xexp#x}"I"$'$x}
```
[Answer]
# R, 53 bytes
```
sum(scan(t=gsub("(.)","\\1 ",x<-scan()))^nchar(x))==x
```
The `gsub` regex inserts spaces in between characters, so that the `scan` function will be able to read the number into a vector of digits.
[Answer]
# Kona, 18
...
```
{x=+/(0$'u)^#u:$x}
```
[Answer]
**Powershell, 75 63 62 60 58** 
Edit: Updated per @Iszi's comment (note: this counts on `$x` not existing)
Edit: Added @Danko's changes.
```
[char[]]($x=$n=read-host)|%{$x-="$_*"*$n.length+1|iex};!$x
```
**58 56 chars**
If input is limited to 10 digits (includes all int32)
```
($x=$n=read-host)[0..9]|%{$x-="$_*"*$n.length+1|iex};!$x
```
[Answer]
## Python 2.x - 51
Same concept as crazedgremlin's solution for Python 3.x:
```
s=input();print s==sum(int(c)**len(`s`)for c in`s`)
```
[Answer]
## C - 97 93 characters
```
a,b;main(c){scanf("%d",&c);b=c;for(;c;c/=10)a+=pow(c%10,(int)log10(b)+1);printf("%d",a==b);}
```
With indentation:
```
a,b;
main(c) { 
  scanf("%d",&c);
  b=c;
  for(;c;c/=10)
    a+=pow(c%10,(int)log10(b)+1);
  printf("%d",a==b);
}
```
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/tree/fb4a2ce2bce6660e1a680a74dd61b72c945e6c3b), 7 bytes
```
DSDgmOQ
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fJdglPdc/8P9/Q1NjAA "05AB1E (legacy) – Try It Online")
-2 bytes thanks to @daHugLenny
[Answer]
# Haskell 2010 - 76 characters
```
main=do x<-getLine;print$(==x)$show$sum$map((^length x).(+(-48)).fromEnum)x
```
[Answer]
# Awk: ~~40~~ 39 characters
```
{for(;i<NF;)s+=$(i+++1)**NF;$0=$0==s}1
```
Sample run:
```
bash-4.1$ awk -F '' '{for(;i<NF;)s+=$(i+++1)**NF;$0=$0==s}1' <<< '153'
1
bash-4.1$ awk -F '' '{for(;i<NF;)s+=$(i+++1)**NF;$0=$0==s}1' <<< '1634'
1
bash-4.1$ awk -F '' '{for(;i<NF;)s+=$(i+++1)**NF;$0=$0==s}1' <<< '2013'
0
```
[Answer]
# Bash, 64 chars
```
for((a=$1;a>0;s+=(a%10)**${#1},a/=10));do :; done;echo $[s==$1]
```
 a=$1;p=${#a};for((;a>0;a/=10));do s=$((s+(a%10)\*\*p));done;echo $((s==$1))
[Answer]
## Lua (101 chars)
Lua isn't known for being concise, but it was fun to try anyway.
```
for n in io.lines()do l,s=n:len(),0 for i=1,l do d=n:byte(i)s=s+(d-48)^l end print(s==tonumber(n))end
```
Improvements welcome.
[Answer]
# Delphi - 166
```
uses System.SysUtils,math;var i,r,l:integer;s:string;begin r:=0;readln(s);l:=length(s);for I:=1to l do r:=round(r+power(strtoint(s[i]),l));writeln(inttostr(r)=s);end.
```
### With indent
```
uses System.SysUtils,math;
var
  i,r,l:integer;
  s:string;
begin
  r:=0;
  readln(s);
  l:=length(s);
  for I:=1to l do
    r:=round(r+power(strtoint(s[i]),l));
  writeln(inttostr(r)=s);
end.
```
[Answer]
## JavaScript - ~~70~~ 58 characters
```
for(i in a=b=prompt())b-=Math.pow(a[i],a.length)
alert(!b)
```
> 
> **Note:**
> 
> 
> If you're testing this in your dev console on Stack Exchange, be aware that there are a number of non-standard properties added to `String.prototype` that will break this solution, such as `String.prototype.formatUnicorn`. Please be sure to test in a clean environment, such as on `about:blank`.
> 
> 
> 
[Answer]
# Java - 84 bytes
```
(a,l)->{int s=0;for(byte c:a.getBytes())s+=Math.pow(c-48,l);return a.equals(""+s);};
```
Non-lambda version: 101 bytes:
```
boolean n(String a,int l){int s=0;for(byte c:a.getBytes())s+=Math.pow(c-48,l);return a.equals(""+s);}
```
Called like this:
```
interface X {
    boolean n(String a, int l);
}
static X x = (a,l)->{int s=0;for(byte c:a.getBytes())s+=Math.pow(c-48,l);return a.equals(""+s);};
public static void main(String[] args) {
    System.out.println(n("153",3));
    System.out.println(n("1634",4));
    System.out.println(n("123",3));
    System.out.println(n("654",3));
}
```
Returns:
```
true
true
false
false
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt/), ~~14~~ ~~9~~ 7 bytes
```
¶ì_xpZÊ
```
[Try it online](https://ethproductions.github.io/japt/?v=1.4.5&code=tuxfeHBayg==&input=MTUz)
---
## Explanation
Implicit input of integer `U`.
```
ì_
```
Convert `U` to an array of digits (`ì`), pass it through a function and convert back to an integer after.
```
xpZÊ
```
Reduce by addition (`x`), raising each element to the power (`p`) of the length (`Ê`) of the array in the process.
```
¶
```
Check if the result is strictly equal to `U`.
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), ~~8~~ 6 bytes
```
f⁰Le∑=
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%C6%9BI%3B%E2%81%B0Le%E2%88%91%3D&inputs=153&header=&footer=)
```
f      # Map each digit to integer
   e   # (for each) to the power of 
 ⁰L    # Input length
    ∑  # Is sum...
     = # Equal to
       # (Implicit input)?
```
-2 thx to lyxal.
[Answer]
## F# - 92 chars
```
let n=stdin.ReadLine()
n|>Seq.map(fun x->pown(int x-48)n.Length)|>Seq.sum=int n|>printf"%b"
```
[Answer]
# Common Lisp - 116 102 characters
```
(defun f(m)(labels((l(n)(if(> n 0)(+(expt(mod n 10)(ceiling(log m 10)))(l(floor n 10)))0)))(= m(l m))))
```
Formatted:
```
(defun f(m)
  (labels((l(n)
            (if(> n 0)
               (+(expt(mod n 10)(ceiling(log m 10)))
                 (l(floor n 10)))
               0)))
    (=(l m)m)))
```
[Answer]
# Smalltalk - 102 99 characters
```
[:n|a:=n asString collect:[:e|e digitValue]as:Array.^n=(a collect:[:each|each raisedTo:a size])sum]
```
At the Workspace, send `value:` with the number, and Print It.
[Answer]
# C#, 117
```
using System.Linq;class A{int Main(string[] a){return a[0].Select(c=>c-'0'^a[0].Length).Sum()==int.Parse(a[0])?1:0;}}
```
]