Created
October 27, 2008 19:47
-
-
Save anonymous/20173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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