Skip to content

Instantly share code, notes, and snippets.

Created October 27, 2008 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/20173 to your computer and use it in GitHub Desktop.
Save anonymous/20173 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
URL: http://projecteuler.net/index.php?section=problems&id=52
Problem summary goes here:
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.
'''
def samedigits(i,j):
sortedi = "".join(sorted(str(i)))
sortedj = "".join(sorted(str(j)))
if sortedi == sortedj:
return True
else:
return False
def main():
n = 1
searching = 1
while searching:
#if n % 1000 == 0:
# print "..",n
if samedigits(n,n*2):
if samedigits(n,n*3):
if samedigits(n,n*4):
if samedigits(n,n*5):
if samedigits(n,n*6):
searching = 0
print "Answer: ", n
n += 1
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment