mirror of
https://gitlab.com/mfocko/CodeWars.git
synced 2024-11-09 19:19:07 +01:00
20 lines
420 B
C#
20 lines
420 B
C#
|
using System;
|
||
|
|
||
|
public class Kata {
|
||
|
public static bool Narcissistic(int value) {
|
||
|
var narcissistic = 0;
|
||
|
var length = (int) Math.Log10(value + 0.5) + 1;
|
||
|
var copyOfValue = value;
|
||
|
|
||
|
while (copyOfValue > 0) {
|
||
|
narcissistic += (int) Math.Pow(copyOfValue % 10, length);
|
||
|
copyOfValue /= 10;
|
||
|
if (narcissistic > value) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return narcissistic == value;
|
||
|
}
|
||
|
}
|