Skip to content

Instantly share code, notes, and snippets.

@Lulzx
Created August 25, 2020 17:59
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 Lulzx/9e7ad7b00ea7b8482400e1ad5da9edfc to your computer and use it in GitHub Desktop.
Save Lulzx/9e7ad7b00ea7b8482400e1ad5da9edfc to your computer and use it in GitHub Desktop.
254
from math import factorial as fac
def f(n: int) -> int:
y = 0
for x in map(int, str(n)):
y += fac(x)
return y
def s(n: int) -> int:
r = 0
while n:
r, n = r + n % 10, n // 10
return r
def sf(n: int) -> int:
return s(f(n))
def g(n: int) -> int:
x = 0
while True:
spi = sf(x)
if spi is n:
return x
else:
x += 1
def sg(n: int) -> int:
return s(g(n))
print(f(342), sf(342), sg(5), g(20))
t = 0
for i in range(1, 21):
t += sg(i)
print(t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment