Project Euler Problem #52 was interesting and easy to solve. The problem states:
Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.
My method of attack was to increment through the positive integers calculating the above products for each. The products were then converted into a string, broken into a list of characters, and finally sorted. The sorted version of the lists for each product were then compared to see if they were all the same. Python code is below.
#!/usr/bin/python
import sys
for x in range(126000,250000):
a2 = list(str(x*2)); a2.sort()
a3 = list(str(x*3)); a3.sort()
a4 = list(str(x*4)); a4.sort()
a5 = list(str(x*5)); a5.sort()
a6 = list(str(x*6)); a6.sort()
if a2 == a3 == a4 == a5 == a6:
print “True! x=”+str(x)
print “a2 “+”.join(a2)+” “+str(x*2)
print “a3 “+”.join(a3)+” “+str(x*3)
print “a4 “+”.join(a4)+” “+str(x*4)
print “a5 “+”.join(a5)+” “+str(x*5)
print “a6 “+”.join(a6)+” “+str(x*6)
else:
if x % 500 == 0:
sys.stdout.write(”.”)
print “Complete”
import sys
for x in range(126000,250000):
a2 = list(str(x*2)); a2.sort()
a3 = list(str(x*3)); a3.sort()
a4 = list(str(x*4)); a4.sort()
a5 = list(str(x*5)); a5.sort()
a6 = list(str(x*6)); a6.sort()
if a2 == a3 == a4 == a5 == a6:
print “True! x=”+str(x)
print “a2 “+”.join(a2)+” “+str(x*2)
print “a3 “+”.join(a3)+” “+str(x*3)
print “a4 “+”.join(a4)+” “+str(x*4)
print “a5 “+”.join(a5)+” “+str(x*5)
print “a6 “+”.join(a6)+” “+str(x*6)
else:
if x % 500 == 0:
sys.stdout.write(”.”)
print “Complete”