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.
First, write a function same_digits(x,y) that returns True if two integers x and y have the exact same set of digits and multiplicities and False if they have different digits.
In [ ]:
def same_digits(x, y):
"""Do the integers x and y have the same digits, regardless of order."""
x=str(x)
y=str(y) #turn the inputs into string
b=[]
k=[]
for i in range(len(x)): # add each individual digit as elements into our empty lists
b.append(x[i])
for i in range(len(y)):
k.append(y[i])
if len(b) != len(k): # ensures that both x and y inputs have the same lengths
return False
else:
for q in range(len(b)): # for each element in list b
for w in range(len(k)):
if q==k[w]: # if that element is equal to the one in k...
return True
else:
return False
In [5]:
x= 125874
y=251748
x=str(x)
y=str(y)
b=[]
k=[]
for i in range(len(x)):
b.append(x[i])
for i in range(len(y)):
k.append(y[i])
In [6]:
b
Out[6]:
In [7]:
k
Out[7]:
In [9]:
f
Out[9]:
In [ ]: