Archive

Archive for July 4, 2019

Python: Permuted Multiples



Python: Permuted Multiples
Problem No.52 @ Projecteuler

This task Completed on Mon, 1 Jul 2019, 06:08, the goal is to find a number X that if we get the X, X*2, X*3, X*4, X*5, X*6 all the numbers are same digits but in a different order.

I use a function called if_x_in_y (n1,n2) will return True if the two numbers has same digits, False if not. Then a while found_one is not True a loop will examine all numbers starting from 2 until we found_one.



The Code:


# Projecteuler.net
# Permuted multiples
# Problem No.52
# Completed on Mon, 1 Jul 2019, 06:08am (GMT+3)

# if x, x*2, x*3, x*4, x*5, x*6 has the same digits.

def if_x_in_y (n1,n2) :

for x in str(n1) :

if x not in str(n2) :

return False

for x in str(n2):

if x not in str(n1):

return False

return True

x_num = 2
found_one= False

while not found_one:

if if_x_in_y(x_num,x_num*2):

if if_x_in_y(x_num,x_num*3):

if if_x_in_y(x_num,x_num*4):

if if_x_in_y(x_num,x_num*5):

if if_x_in_y(x_num,x_num*6):

print(‘\n Yes, we found one ..’)

found_one = True

print(‘ The Number is ‘,x_num)

x_num += 1

print(x_num,x_num*2,x_num*3,x_num*4,x_num*5,x_num*6)






Follow me on Twitter..