-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler-p92.py
More file actions
29 lines (27 loc) · 854 Bytes
/
Copy patheuler-p92.py
File metadata and controls
29 lines (27 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 13 18:41:44 2025
@author: phoebeliu
"""
## https://thecprojectt.blogspot.com/2014/10/square-digit-chains-problem-92-project.html
## brute force sol, very slow
def squareDigitChains():
squareDigitCount = 0
for i in range(1,10000000):
strnumber = ""
strnumber = str(i)
sqnumber = 0
temp = strnumber
while True:
sqnumber = 0
for j in range(len(strnumber)):
sqnumber = sqnumber + int(strnumber[j])**2
strnumber = str(sqnumber)
if sqnumber == 1 or sqnumber == 89:
break
if sqnumber == 89:
print(temp)
squareDigitCount = squareDigitCount + 1
print("Required Counter is:",squareDigitCount)
squareDigitChains()