mirror of
https://github.com/correl/euler.git
synced 2024-11-27 11:09:54 +00:00
Problem 052
git-svn-id: file:///srv/svn/euler@69 e5f4c3ec-3c0c-11df-b522-21efaa4426b5
This commit is contained in:
parent
bd19185828
commit
3b11a2d0b9
1 changed files with 31 additions and 0 deletions
31
e052.py
Normal file
31
e052.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
"""Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits in some order.
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
MAX = 6
|
||||
|
||||
def main():
|
||||
i = 1
|
||||
while True:
|
||||
digits = sorted([int(c) for c in str(i)])
|
||||
d = [int(c) for c in str(i * MAX)]
|
||||
if len(d) > len(digits):
|
||||
# No chance of matching, jump ahead to the new digit count
|
||||
i = 10**(len(d) - 1)
|
||||
print 'Jumping to', i
|
||||
continue
|
||||
try:
|
||||
for multiplier in range(2, MAX + 1):
|
||||
if sorted([int(c) for c in str(i * multiplier)]) != digits:
|
||||
raise Exception()
|
||||
print 'Smallest number with same digits in multiples up to {0}x: {1}'.format(MAX, i)
|
||||
break
|
||||
except:
|
||||
pass
|
||||
i = i + 1
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in a new issue