interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / narcissistic-decimal-number / oracle.py

13 lines · 676 bytes Raw Blame History
1# Independent reference for "Narcissistic decimal number" (Python 3, standard library only).
2# expected.txt is this program's stdout; omc never produced it.
3# by digit multisets: for each length k and each sorted choice of k digits, the power sum is
4# narcissistic when its own digits, sorted, are that choice
5import itertools
6found = set()
7for k in range(1, 8):
8 for combo in itertools.combinations_with_replacement(range(10), k):
9 s = sum(d ** k for d in combo)
10 if len(str(s)) == k and tuple(sorted(map(int, str(s)))) == combo:
11 found.add(s)
12found.add(0)
13print("first 25 narcissistic decimal numbers: " + " ".join(map(str, sorted(found)[:25])))