Created
May 21, 2020 08:45
-
-
Save Kush1101/08e3a82195948e8c18e3cce138f6c5de to your computer and use it in GitHub Desktop.
Project Euler Problem 52 solution @ https://projecteuler.net/problem=52
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
import time | |
import sys | |
a=time.time() | |
def same(n): | |
return sorted(str(n))==sorted(str(2*n)) ==\ | |
sorted(str(3*n))==sorted(str(4*n))==sorted(str(5*n)) | |
""" | |
Here I have tried to optimize the performance by chekcing only the numbers from n to 2n | |
For example I am checking only 100-200, 1000-2000,10000-20000,100000-200000 etc. | |
This is because any number above this range will exceed the given number of digits if you | |
multiply it by 6. | |
This allows us to check through large numbers quickly | |
""" | |
for i in range(1,10): | |
print(10**i,2*(10**i)+1) | |
for j in range(10**i,2*(10**i)+1): | |
if same(j): | |
print(j) | |
print(time.time()-a) | |
sys.exit('Found it!') | |
#142857 | |
#Interestingly, in the repititive decimal notation of 1/7 the cycle is 0.142857 142857..... !! :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment