Skip to content

Instantly share code, notes, and snippets.

@michaelsoltys
Created October 20, 2023 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelsoltys/d05d8a386eb9f55716019e112f987ee9 to your computer and use it in GitHub Desktop.
Save michaelsoltys/d05d8a386eb9f55716019e112f987ee9 to your computer and use it in GitHub Desktop.
Sum of powers of digits
import math
# replace 999999999 with upper limit of your choice
for i in range(1, 999999999):
i_as_string = str(i)
i_as_list = []
j = 1
output = 0
for digits in i_as_string:
output += pow(int(digits),j)
j += 1
if output == i:
j = 0
for digits in i_as_string:
j += 1
print(digits, "^", j, sep = "", end = "")
if j < len(i_as_string):
print(" + ", end = "")
print (" = ", i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment