def remove_digits(number): from maths.misc import get_digits, digit_list_to_num digits = get_digits(number) num_digits = len(digits) for i in xrange(1, num_digits): # Remove digits from the right yield digit_list_to_num(digits[:i]) # Remove digits from the left yield digit_list_to_num(digits[i:])
def list_to_num(digits): length = len(digits) num = 0 for i in xrange(length): power = length - 1 - i num += digits[i] * 10**power return num if __name__ == "__main__": from maths.misc import get_digits, is_prime circular_primes = [] for i in xrange(2, 1000000): if not is_prime(i): continue prime = True digits = get_digits(i) for offset in xrange(1,len(digits)): shifted = shift_digits(digits, offset) num = list_to_num(shifted) if not is_prime(num): prime = False break if prime: circular_primes.append(i) print('The number of circular primes below 1,000,000 is %d'%len(circular_primes))
# We don't want to "over-reduce" if num % i == 0 and denom % i == 0: num = num / i denom = denom / i return num, denom if __name__ == "__main__": from maths.misc import get_digits numerators = [] denominators = [] for i in xrange(10,100): for j in xrange(i + 1,100): # Get digits of i,j digits_i, digits_j = get_digits(i), get_digits(j) # Check for overlap overlap = filter(set(digits_i).__contains__, digits_j) if len(overlap) > 0: # Pull first char from overlap char_to_remove = overlap[0] # Check for trivial case where digits to be removed are in the same power of 10s position index_i = digits_i.index(char_to_remove) index_j = digits_j.index(char_to_remove) if index_i == index_j: # Trivial case continue