Skip to content

Instantly share code, notes, and snippets.

@Eliran-Turgeman
Created October 25, 2020 10:42
Show Gist options
  • Save Eliran-Turgeman/be040ceeb8c124ca957738e1ac93fe65 to your computer and use it in GitHub Desktop.
Save Eliran-Turgeman/be040ceeb8c124ca957738e1ac93fe65 to your computer and use it in GitHub Desktop.
steinhaus_cycle
def sum_of_squared_digits(n):
digits = [i for i in str(n)]
sum = 0
for digit in digits:
sum += int(digit)**2
return sum
iter = 0
iters = []
for n in range(1, 127):
while int(n) not in [1,4,16,37,58,89,145,42,20]:
iter += 1
n = sum_of_squared_digits(n)
iters.append(iter)
iter = 0
for i, n in enumerate(iters):
print(f'Number {i+1} in {n} iterations')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment