It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.
Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.
from time import time
def is_permutation(n1, n2):
"""returns True if n1 is permutation of n2"""
if n1 == n2:
return False
str1 = str(n1)
str2 = str(n2)
digits1 = {digit: str1.count(digit) for digit in str1}
digits2 = {digit: str2.count(digit) for digit in str2}
if not digits1 == digits2:
return False
return True
def check_multiples(n, start=10):
"""checks 2x, 3x, 4x, 5x, 6x and returns the numbers if they are permutations."""
for x1 in range(start, n):
x2 = x1 * 2
if is_permutation(x1, x2):
x3 = x1 * 3
if is_permutation(x2, x3):
x4 = x1 * 4
if is_permutation(x3, x4):
x5 = x1 * 5
if is_permutation(x4, x5):
x6 = x1 * 6
if is_permutation(x5, x6):
return x1, x2, x3, x4, x5, x6
if __name__ == '__main__':
start_time = time()
print(check_multiples(1000000, 125000)[0])
print(f'Time: {time() - start_time} seconds.')