Last active
October 9, 2019 22:11
-
-
Save motatoes/73dc99e41d4036b56c03655fede172c4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# this function takes a number and returns true if the digits of `n` are distinct otherwise returns false | |
def valid(n): | |
return len(set(str(n))) == len(str(n)) | |
# this variable will hold the maximum range found so far | |
mrange = 0 | |
# this variable keeps track of the start for our range | |
start = 0 | |
for i in range(10**5): | |
if valid(i): | |
#if i is valid lets mark that range | |
print(i) | |
# did we found a range greater than the max range found already? | |
if mrange < i - start : | |
mrange = i - start | |
mstart = start | |
mend = i | |
start = i | |
# prints the maximum range, where it starts and where it ends | |
print(mrange, mstart, mend) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment