Skip to content

Instantly share code, notes, and snippets.

@dstoza
Created May 30, 2018 21:26
Show Gist options
  • Save dstoza/ad18b7c1e59815e1f2b575c9515e0d5d to your computer and use it in GitHub Desktop.
Save dstoza/ad18b7c1e59815e1f2b575c9515e0d5d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
def get_init(factor):
values = []
for i in range(1, 10):
s = str(i)
s = str((i * factor) % 10) + s
while s[0] == '0':
s = str((int(s) * factor) // 10) + s
values += [s]
return values
def comp(factor, i):
while str(int(i) * factor) != i[-1:] + i[:-1]:
p = str(int(i) * factor)
i = p[-len(i):-(len(i)-1)] + i
if i[0] == '0':
return None
return int(i)
def get_best(factor):
best = None
for v in get_init(factor):
c = comp(factor, v)
if not best or c and c < best:
best = c
return best
for factor in range(2, 10):
best = get_best(factor)
print(factor, best, len(str(best)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment