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 def euler_052(): for i in range(100000, 200000): if check_if_multiples_contain_same_digits(i, 6): return i if __name__ == "__main__": print("e052.py: " + str(euler_052())) assert(euler_052() == 142857)