We're a place where coders share, stay up-to-date and grow their careers.
This is fun! Here is a Python 3.5 one-liner with only one calculation of the length of nb per nb :
print([nb for nb in range(10000) if nb == sum(int(c)**l for l in [len(str(nb))] for c in str(nb))])
And now with also one conversion of str(nb) per nb:
print([nb for nb in range(10000) if nb == sum(int(c)**l for str_nb in [str(nb)] for l in [len(str_nb)] for c in str_nb)])
This is fun! Here is a Python 3.5 one-liner with only one calculation of the length of nb per nb :
print([nb for nb in range(10000) if nb == sum(int(c)**l for l in [len(str(nb))] for c in str(nb))])
And now with also one conversion of str(nb) per nb:
print([nb for nb in range(10000) if nb == sum(int(c)**l for str_nb in [str(nb)] for l in [len(str_nb)] for c in str_nb)])