Return True if n is a pluperfect number or False if it is not >>> all(pluperfect_number(n) for n in PASSING) True >>> any(pluperfect_number(n) for n in FAILING) False
(n: int)
| 41 | |
| 42 | |
| 43 | def pluperfect_number(n: int) -> bool: |
| 44 | """Return True if n is a pluperfect number or False if it is not |
| 45 | |
| 46 | >>> all(pluperfect_number(n) for n in PASSING) |
| 47 | True |
| 48 | >>> any(pluperfect_number(n) for n in FAILING) |
| 49 | False |
| 50 | """ |
| 51 | if not isinstance(n, int) or n < 1: |
| 52 | return False |
| 53 | |
| 54 | # Init a "histogram" of the digits |
| 55 | digit_histogram = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] |
| 56 | digit_total = 0 |
| 57 | total = 0 |
| 58 | temp = n |
| 59 | while temp > 0: |
| 60 | temp, rem = divmod(temp, 10) |
| 61 | digit_histogram[rem] += 1 |
| 62 | digit_total += 1 |
| 63 | |
| 64 | for cnt, i in zip(digit_histogram, range(len(digit_histogram))): |
| 65 | total += cnt * i**digit_total |
| 66 | |
| 67 | return n == total |
| 68 | |
| 69 | |
| 70 | def narcissistic_number(n: int) -> bool: |