2019-07-18 03:29:59 +02:00
|
|
|
def get_digits_count(n):
|
|
|
|
digits_count = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
|
|
for d in str(n):
|
|
|
|
digits_count[int(d)] += 1
|
|
|
|
return digits_count
|
|
|
|
|
|
|
|
|
|
|
|
assert(get_digits_count(1258744) == [0, 1, 1, 0, 2, 1, 0, 1, 1, 0])
|
|
|
|
|
|
|
|
|
|
|
|
def check_if_multiples_contain_same_digits(n, max_multiple=2):
|
|
|
|
|
|
|
|
def get_length(n):
|
|
|
|
return len(str(n))
|
|
|
|
|
|
|
|
n_digits_count = get_digits_count(n)
|
|
|
|
n_length = get_length(n)
|
|
|
|
n_multiple = n * max_multiple
|
|
|
|
while n != n_multiple:
|
|
|
|
if n_length != get_length(n_multiple) \
|
|
|
|
or n_digits_count != get_digits_count(n_multiple):
|
|
|
|
return False
|
|
|
|
n_multiple -= n
|
|
|
|
return True
|
|
|
|
|
2019-07-17 03:17:21 +02:00
|
|
|
|
|
|
|
def euler_052():
|
2019-07-18 03:29:59 +02:00
|
|
|
for i in range(100000, 200000):
|
|
|
|
if check_if_multiples_contain_same_digits(i, 6):
|
|
|
|
return i
|
2019-07-17 03:17:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
print("e052.py: " + str(euler_052()))
|
2019-07-18 03:29:59 +02:00
|
|
|
assert(euler_052() == 142857)
|