-
-
Save al3x/20174 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))) | |
return sortedi == sortedj | |
def main(): | |
n = 1 | |
while True: | |
runs = [] | |
for i in [2, 3, 4, 5, 6]: | |
runs.append(samedigits(n, n * i)) | |
if False in runs: | |
n += 1 | |
else: | |
print "Answer: %d" % n | |
exit(0) | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment