-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
29 lines (24 loc) · 793 Bytes
/
main.py
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
start = 1
end = 10000
stepdict = []
def differenceofsorted(x):
global steps
a = int("".join(sorted(str(x))).strip())
d = int("".join(sorted(str(x), reverse=True)).strip())
q = d - a
print(x, " : ", d, " - ", a, "= ", q)
if q == 6174: # 4-digit Kaprekar constant
print("Goal Reached for: ", x, "in ", steps, " steps")
elif q == 495: # 3-digit Kaprekar constant
print("Goal Reached for: ", x, "in ", steps, " steps")
elif q == 0:
print("Zero difference encountered for :", x, "in ", steps, " steps")
else:
steps += 1 # increment step counter
differenceofsorted(q)
return steps
# Loop through all 4-digit numbers
for n in range(start, end):
steps = 1
differenceofsorted(n)
stepdict.append(steps)