Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.0 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69cfca90e8a0a6d4d6871c52 Challenge 268: Narcissistic Number 29 challenge-268

--description--

Given a positive integer, determine whether it is a narcissistic number.

  • A number is narcissistic if the sum of each of its digits raised to the power of the total number of digits equals the number itself.

For example, 153 has 3 digits, and 13 + 53 + 33 = 153, so it is narcissistic.

--hints--

is_narcissistic(153) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_narcissistic(153), True)`)
}})

is_narcissistic(154) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_narcissistic(154), False)`)
}})

is_narcissistic(371) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_narcissistic(371), True)`)
}})

is_narcissistic(512) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_narcissistic(512), False)`)
}})

is_narcissistic(9) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_narcissistic(9), True)`)
}})

is_narcissistic(11) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_narcissistic(11), False)`)
}})

is_narcissistic(9474) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_narcissistic(9474), True)`)
}})

is_narcissistic(6549) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_narcissistic(6549), False)`)
}})

--seed--

--seed-contents--

def is_narcissistic(n):

    return n

--solutions--

def is_narcissistic(n):
    digits = str(n)
    power = len(digits)
    return sum(int(d) ** power for d in digits) == n