project-euler/168_number_rotations.py

23 lines
557 B
Python
Raw Normal View History

2023-03-25 17:24:17 +01:00
#!/usr/bin/env python3
def search(i, k, fst, dig=None, r=0, num=str()):
if dig == None:
dig = fst
if i == 0:
return False
n = k*dig + r
if n < 10 and fst == n and dig != 0:
return str(dig) + num
return search(i-1, k, fst, n%10, n//10, str(dig) + num)
places = 100
s = 0
for k in range(1, 10):
for dig in range(1, 10):
n = search(places, k, dig)
if n:
r = places // len(n)
for i in range((1 + (len(n)==1)), r+1):
s += int(i*n) % 10**5
print(s % 10**5)