Skip to content

Is narcissistic #6052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 32 commits into from
Closed
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
00c22a3
Added censor function
meg-1 May 16, 2021
4194344
Added censor code
meg-1 May 17, 2021
e7d4102
Added comments to the code
meg-1 May 17, 2021
93bd4ac
modified censor function
meg-1 May 22, 2021
b714278
added decrypt function
meg-1 Aug 1, 2021
c879c7f
added cypher and decypher functions, deleted censor and decrypt funct…
meg-1 Aug 4, 2021
e60dd6f
Deleted decrypt.py
meg-1 Aug 4, 2021
b3e0cb8
Deleted censor.py
meg-1 Aug 4, 2021
e14b9ef
Merge branch 'TheAlgorithms:master' into master
meg-1 Aug 4, 2021
947f7d8
edited the crypt and decrypt files
meg-1 Aug 4, 2021
daf21ad
Update cypher_txt.py
meg-1 Aug 4, 2021
d3d8b29
Remove the endline in cypher.py
meg-1 Aug 4, 2021
752c197
Removed the print at the end of decypher.py
meg-1 Aug 4, 2021
9f44028
comitting changes
meg-1 Aug 18, 2021
f72431b
added 4 new algorithms
meg-1 Aug 18, 2021
4c891f4
added tests to the four files
meg-1 Aug 25, 2021
c600b10
added type hints for the function variables
meg-1 Aug 25, 2021
4286e40
Merge branch 'TheAlgorithms:master' into master
meg-1 Dec 11, 2021
7a909e2
Deleted decode message
meg-1 Dec 25, 2021
f5b5411
Deleted code message
meg-1 Dec 25, 2021
bc8388c
Welford average algorithm
meg-1 Jan 29, 2022
9be479e
added average welford algorithm
meg-1 Feb 9, 2022
f3fb7e6
is_narcissistic added
meg-1 Mar 19, 2022
d00d135
added a descriptive name
meg-1 Mar 23, 2022
0fd2747
decrypt.py
meg-1 Apr 6, 2022
71e1492
Merge pull request #1 from meg-1/decrypt
meg-1 Apr 6, 2022
59a3c04
deleted decrypt.py
meg-1 Apr 9, 2022
3060e3e
deleted censor.py [ is in the wrong pr ]
meg-1 Apr 16, 2022
4d0856c
deleted average_welford [ also in the wrong pr ]
meg-1 Apr 16, 2022
9ad611f
fixed errors with tests
meg-1 Apr 16, 2022
1c3c89c
added indendation
meg-1 Apr 20, 2022
0ea36ea
removed indent
meg-1 Apr 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions maths/is_narcissistic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def is_narcissistic(num: int) -> bool:

"""
>>> is_narcissistic(1527)
False
>>> is_narcissistic(-1527)
False
>>> is_narcissistic(153)
True
>>> is_narcissistic("153")
True
"""

"""In number theory, a narcissistic number is a number that is
the sum of its own digits each raised to the power of the number of digits.
this alogrithm finds out if given number 'num' is narcissistic or not"""

num = abs(int(num))
return sum([int(char)**len(str(num)) for char in str(num)]) == num


if __name__ == "__main__":
import doctest
doctest.testmod()