Created
February 16, 2016 15:22
-
-
Save harshithjv/969f4fb820dd96e4739c to your computer and use it in GitHub Desktop.
Mimics the Base 5 number system as a generator function.
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
| def get_5x_increments(num): | |
| num_str = str(num) | |
| num_len = len(str(num)) | |
| if num_str[-1:] == '4': | |
| new_num = num + 6 | |
| if '5' in str(new_num): | |
| return 6 + get_5x_increments(new_num) | |
| else: | |
| return 6 | |
| if '5' in num_str: | |
| for i in xrange(num_len): | |
| five_zeroes = '5' + '0' * (num_len - i - 1) | |
| if five_zeroes == num_str[i:]: | |
| five_zeroes_int = int(five_zeroes) | |
| if '5' in str(num + five_zeroes_int): | |
| return five_zeroes_int + get_5x_increments(num + five_zeroes_int) | |
| return five_zeroes_int | |
| return 1 | |
| def digits_0to5(n): | |
| i = 0 | |
| while i < n and i < 50000: | |
| yield i | |
| i += get_5x_increments(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment