Created
October 25, 2020 10:42
-
-
Save Eliran-Turgeman/be040ceeb8c124ca957738e1ac93fe65 to your computer and use it in GitHub Desktop.
steinhaus_cycle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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