Created
October 4, 2013 01:27
-
-
Save danibrear/6819674 to your computer and use it in GitHub Desktop.
python program to figure out how many numbers there are between 1-x with repeating digits.
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
def get_digits(num): | |
rem = num % 10 | |
it_num = num/10 | |
digits = [] | |
while(rem > 0 or it_num > 0): | |
if rem in digits: return None | |
digits.insert(0, rem) | |
rem = it_num % 10 | |
it_num = it_num/10 | |
return num | |
if __name__ == '__main__': | |
num = 1000 | |
digits = [] | |
for x in range(1,num+1): | |
solution = get_digits(x) | |
if solution: | |
digits.append(solution) | |
print len(digits) | |
print num - len(digits) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment