Skip to content

Instantly share code, notes, and snippets.

@al3x
Forked from anonymous/euler 52
Created October 27, 2008 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save al3x/20174 to your computer and use it in GitHub Desktop.
Save al3x/20174 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)))
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